Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Twig Link Attributes

No security coverage Under active development 106 sites

Part of the Twig ecosystem · 43 projects

This module provides a Twig filter to add attributes to links in templates. It merges new attributes with existing ones, preventing them from being overwritten. This allows themes and other modules to add attributes without conflicts.

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']})) }}

Drupal 9–10 · not 11

Ask your assistant about Twig Link Attributes

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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.

Activity

Tracked releases
1
Tracked since
Jan 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
8.x-2.0 Stable 9–10 Jan 23, 2023