title: Conditional class with Twig on div element
body: <p>Can I change class added to a div element depending on the content of this div ?
  Like: "if the div is empty, add this class, else add this class" and targeting the div with an id or something else.</p>
  
  <p>If yes, how can I do that ?
  Thanks</p>
  
  <p>EDIT: I found a workaroud like this</p>
  
  <pre><code>{% set vueBlocArchives_classes = [
  'liste-archives',
  'type-' ~ node.bundle|clean_class
  ]%}
  {% set vuebloc_classes = [
  'liste-vdl',
  'type-' ~ node.bundle|clean_class
  ]%}
  {% set vueBlocInfoAdmin_classes = [
  'liste-info-admin',
  'type-' ~ node.bundle|clean_class
  ]%}
  </code></pre>
  
  <p>then I do:</p>
  
  <pre><code>  {% if node.field_inserer_liste_viewfield is not empty and node.id == 77 %}
        &lt;aside {{ vuebloc_attribute.addClass(vueBlocArchives_classes) }}&gt;
          {{ content.field_inserer_liste_viewfield.0 }}
        &lt;/aside&gt;
        {# Change classe selon le Nid - Ici nid de la page Info Admin #}
      {% elseif node.field_inserer_liste_viewfield is not empty and node.id == 125 %}
        &lt;aside {{ vuebloc_attribute.addClass(vueBlocInfoAdmin_classes) }}&gt;
          {{ content.field_inserer_liste_viewfield.0 }}
        &lt;/aside&gt;
      {% else %}
        &lt;aside {{ vuebloc_attribute.addClass(vuebloc_classes) }}&gt;
          {{ content.field_inserer_liste_viewfield.0 }}
        &lt;/aside&gt;
      {% endif %}
  </code></pre>
  
  <p>But I need to repeat the code so I thought about putting in a variable this part:</p>
  
  <pre><code> {{ content.field_inserer_liste_viewfield.0 }}
            &lt;/aside&gt;
  </code></pre>
  
  <p>@sakhunzai tip can be a better way, but how can I use it with my code ?</p>
  
  <p>EDIT2: test to put static code in a variable but syntax errored</p>
  
  <pre><code>  {% set finAside = content.field_inserer_liste_viewfield.0 | render | trim "&lt;/aside&gt;" %}
      {# Change classe selon Nid - Ici nid de la page archives #}
      {% if node.field_inserer_liste_viewfield is not empty and node.id == 77 %}
        &lt;aside {{ vuebloc_attribute.addClass(vueBlocArchives_classes) }}&gt;
          {{ finAside }}
  </code></pre>
  
  <p>Instead this work:</p>
  
  <pre><code>{% if node.field_inserer_liste_viewfield is not empty %}
        {# Change classe selon Nid - Ici nid de la page archives #}
        {% if node.field_inserer_liste_viewfield is not empty and node.id == 77 %}
          &lt;aside {{ vuebloc_attribute.addClass(vueBlocArchives_classes) }}&gt;
  
            {# Change classe selon le Nid - Ici nid de la page Info Admin #}
          {% elseif node.field_inserer_liste_viewfield is not empty and node.id == 125 %}
            &lt;aside {{ vuebloc_attribute.addClass(vueBlocInfoAdmin_classes) }}&gt;
  
            {% else %}
              &lt;aside {{ vuebloc_attribute.addClass(vuebloc_classes) }}&gt;
              {% endif %}
              {{ content.field_inserer_liste_viewfield.0 }}
            &lt;/aside&gt;
          {% endif %}
  </code></pre>
  
  <p>Inspired by <a href="https://stackoverflow.com/a/42144678/2416915">https://stackoverflow.com/a/42144678/2416915</a>
  I posted another question similar of these : <a href="https://stackoverflow.com/q/59289461/2416915">Is it possible to use Twig addClass with condition?</a></p>