Twig attribues.addclass nesting issue Apologies if this has been asked before, but I'm on my first week working with drupal and twig.
I have the following code:
{%
  set container_classes = [
    'paragraph',
    'paragraph--type--' ~ paragraph.bundle|clean_class,
    view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
    not paragraph.isPublished() ? 'paragraph--unpublished',
    'container'  
  ]  
%}
{% set image_classes = [
  'col-12'  
]
%}
{% block paragraph %}  
  
  {% block content %}
    &lt;div{{ attributes.addClass(container_classes) }}&gt;
      &lt;div class='row'&gt;
        &lt;div{{ attributes.addClass(image_classes) }} data-type='image'&gt;
          {{ content.field_two_column_image }}          
        &lt;/div&gt;
        &lt;div class='col-12 col-lg-auto' data-type='copy'&gt;
          {{ content.field_two_column_copy }}
        &lt;/div&gt;
      &lt;/div?&gt;
    &lt;/div&gt;          
  {% endblock %}
 
{% endblock paragraph %}


My issue is the nested attributes.addClass. When I look at the HTML, I'm also seeing the container_classes classes, which is not what I'm looking for.
So how can I separate the two?
attributes is a variable containing attributes information (class, id, others..) for the main container of the template.
It should usually be used only once.
You can create a new attribute variable like this :
{% set my_attribute = create_attribute() %}|
And you can use it as usual :
&lt;div{{ my_attribute.addClass(image_classes).setAttribute('data-type', 'image') }}&gt;
  {{ content.field_two_column_image }}          
&lt;/div&gt;

More information about using the attributes variable in Twig templates :
https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templates
https://www.drupal.org/docs/8/theming-drupal-8/modifying-attributes-in-a-theme-file
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/8.2.x