Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

twig

symfony

I'm trying to create a link with an anchor like "www.example.com/services#anchor1" in my Twig template. So far I've been using the path function to create links path('services'). I have tried with path('services#anchor1') but obviously it doesn't work.

It doesn't seem to be a lot of information about this function or it's just that I can't find it. Any idea about how could I do it?

Thanks!

like image 733
lgomezma Avatar asked Jan 09 '12 20:01

lgomezma


2 Answers

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

like image 121
madflow Avatar answered Nov 14 '22 14:11

madflow


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.

like image 37
COil Avatar answered Nov 14 '22 16:11

COil