Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By darkdim on
Hi, all!
I have html code: <a href="about-us.html"><i class="fa fa-angle-right"></i> About Us</a>
In template this link output as {{ link('item.title, item.url) }}
If I added tag i to title: {{ link('<i class="fa fa-angle-right"></i> ' ~ item.title, item.url) }}
Then result on screen <i class="fa fa-angle-right"></i> About Us
http://www.screencast.com/t/AJEldPRiA
How to add tags to the text link?
Comments
You can't do that with twigs
You can't do that with twigs link function. You'd do it something like this:
<li><i class="fa fa-angle-right"></i>{{ link(item.title, item.url) }}</li>
If you want the icon inside the
<a></a>
consider a different method, such as using theurl()
function instead: https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templatesPimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Hi, Jeff!
Hi, Jeff!
Thank you for your answer!
I solved this issue in a way:
But I want to understand, maybe there is a more elegant solution...
Ha, I think thats fine,
Ha, I think thats fine, perfectly elegant solution!
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
How did you get this to work,
How did you get this to work, link() seems to be escaping the html i set in 'title'.
Ryan aka Devkinetic
Sr. Web Developer
This piece of code allows the
This piece of code allows the link to pass markup
Thank you
Thank you so much )
You are probably trying to
You are probably trying to set your title this way :
{% set title = '<span class="glyphicon'></span>' ~ item.title %}
And it's not working ... was running under the same issue.
Actually the elegant solution is to use {% set %} and {% endset %}, so you can write html between the tags.
Wow, thanks for clarifying
Wow, thanks for clarifying that there is a difference!
This works:
And this does NOT work:
I would have thought that both are the same and run through the same filtering and escaping operations in Twig, but alas, they seem to be different.
Daniel 'sun' Kudwien
makers99
Thank you!
Thank you! It works for me!
I got the same issue I gave
I got the same issue I gave it a try with hooks but nothing works. Finally I did same as you guys:
But I still think there's another way to put HTML as a title same same as in D7 I remember we set a HTML attribute as TRUE in l() function ...
Thank you!
Thank you! It works for me!