

{% import _self as m %}

{# The 4 fields to group #}
{% set main_fields = ['field_images', 'title', 'field_sous_titre', 'view_node'] %}

{# Macro that renders a field exactly like the default loop #}
{% macro render_field(field) %}
  {{ field.separator }}
  {% if field.wrapper_element %}<{{ field.wrapper_element }}{{ field.wrapper_attributes }}>{% endif %}

  {% if field.label %}
    {% if field.label_element %}
      <{{ field.label_element }}{{ field.label_attributes }}>{{ field.label }}{{ field.label_suffix }}</{{ field.label_element }}>
    {% else %}
      {{ field.label }}{{ field.label_suffix }}
    {% endif %}
  {% endif %}

  {% if field.element_type %}
    <{{ field.element_type }}{{ field.element_attributes }}>
      {{ field.content }}
    </{{ field.element_type }}>
  {% else %}
    {{ field.content }}
  {% endif %}

  {% if field.wrapper_element %}</{{ field.wrapper_element }}>{% endif %}
{% endmacro %}


{% set raw_title = fields.title.content|striptags|trim %}
{% set title_first = raw_title|split(',')|first|trim %}
{% set title_slug = title_first|clean_class %}

<div class="views-field-group {{ title_slug }}">
  {% for name in main_fields %}
    {% if fields[name] is defined %}
      {{ m.render_field(fields[name]) }}
    {% endif %}
  {% endfor %}
</div>

{% for name, field in fields %}
  {% if name not in main_fields %}
    {{ m.render_field(field) }}
  {% endif %}
{% endfor %}


