Answers for "Drupal 8 Attributes"

0

attribute drupal 8

<div{{ attributes.addClass('my-class') }}></div>

{% set classes = [ 'red', 'green', 'blue' ] %}
<div{{ attributes.addClass(classes).removeClass('green') }}></div>

<div{{ attributes.setAttribute('id', 'myID') }}></div>
<div{{ attributes.removeAttribute('id') }}></div>
<div style="{{ attributes.style }}"></div>

{% if attributes.hasClass('myClass') %}
  {# do stuff #}
{% endif %}

{% if attributes['data-my-data'] %}
  {# do stuff #}
{% endif %}

<div class="myclass {{ attributes.class }}"{{ attributes|without('class') }}></div>

{% set my_attribute = create_attribute() %}
{%
  set my_classes = [
	'your class'
  ]
%}
<div{{ my_attribute.addClass(my_classes).setAttribute('id', 'myUniqueId') }}>
  {{ content }}
</div>
Posted by: Guest on August-13-2020

Browse Popular Code Answers by Language