Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Adding Markup to Menu Links in Drupal 8

The best (and safest) way to add markup to menu links in Drupal 8 is by editing the appropriate menu template in your theme.

Cases where it may be useful to include HTML markup within a menu item anchor link would be to add a drop-down icon for an expanded menu item.

Here's an example within menu.html.twig:

{% set title %}
  {{ item.title }} <i class="ti-angle-down"></i>
{% endset %}

 

{{ link(title, item.url, item.attributes.addClass('dropdown-toggle')) }}