nnikolay
nnikolay

Reputation: 1751

Symfony href shoud work for app_dev.php and app.php

I have in Twig an link:

link

Which outputs as url: www.domain.com/category-laptops

But on dev I need to output: www.domain.com/app_dev.php/category-laptops

Is there some function for this, or should I write by my own based on the environment?

Thanks Nik

Upvotes: 0

Views: 433

Answers (2)

Samuel Cloete
Samuel Cloete

Reputation: 332

If you've set up the route correctly then path('route_name') should give you the correct link in both environments.

Upvotes: 1

Roman
Roman

Reputation: 2549

You have to use {{ path() }} in your twig-template for that.

example:

<a href="{{ path('article_show', {'slug': article.slug}) }}">
    {{ article.title }}
</a>

See: http://symfony.com/doc/current/reference/twig_reference.html#path

If you want to use absolute links, you can use {{ url() }} instead of {{ path() }}

See: http://symfony.com/doc/current/reference/twig_reference.html#url

Upvotes: 3

Related Questions