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']})) }}
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Twig ecosystem
Most installed first
Activity
Releases
| Version | Type | Core | Release date | |
|---|---|---|---|---|
| 8.x-2.0 | Stable | Jan 23, 2023 |