Created
November 29, 2018 14:53
-
-
Save achraf-jeday/fa8c326eb659a8cbfa3d12aa61ac5a02 to your computer and use it in GitHub Desktop.
TWIG Add classes to attributes array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attributes.addClass() | |
Adds classes or merges them on to array of existing CSS classes. | |
Single class: | |
<div{{ attributes.addClass('my-class') }}></div> | |
Multiple classes: | |
{% | |
set classes = [ | |
'red', | |
'green', | |
] | |
%} | |
<div{{ attributes.addClass(classes) }}></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templates