Create a link with an anchor with Twig path function in Symfony 2 Create a link with an anchor with Twig path function in Symfony 2 symfony symfony

Create a link with an anchor with Twig path function in Symfony 2


Try <a href="{{ path('_welcome') }}#home">Home</a>


As of Symfony 3.2 you can use the _fragment option:

<a href="{{ path('homepage', {'_fragment': 'home'}) }}">Home</a>

Check out the feature introduction on the Symfony blog.


I had the same problem. I had just link being generated in the a tag but then needed to open in a new page aka add target="_blank" to the generated url so I changed the href to this and it worked!

<a class="new-item"  target="_blank" href="{{ link(item.title, item.url) }}"></a>