Search code examples
phpsymfonyhref

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


Solution

  • 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