attribute drupal 8
snippet in html

attribute drupal 8

user1801

<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>