Twig Link Attributes
Categories
Component ID
2809035
Component name
Twig Link Attributes
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
311
Component created
Component changed
Component body
Simple twig filter to add attributes to link() item.url's in templates.
Has the advantage of merging attributes so modules like Menu Link Attributes do not have their attributes blown away in the template.
For example, current documentation encourages themers to do this:
{{ link(item.title, item.url, { 'class':['menu__link']}) }}
However classes added via preprocess or Menu Link Attributes will no longer be applied, as the above code blows them away.
Usage:
Filter: link_attributes('attribute type':[attribute values])
E.g. in menu.html.twig you can do stuff like this:
{{ link(item.title, item.url|link_attributes({'class' : ['menu__link'], 'data-drupal-example' : ['is-item']})) }}
