theming – Is it possible to pass classes to twig include template

Drupal 9 bootstrap barrio sub-theme.

I would like to use a generic template to build some “card” bootstrap display. This template is called by multiple other templates like this :

{% include '@my_theme/views/views-view-unformatted--card-template.html.twig %}

At begining, I started with this template :

{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
<div class="card-view row row-cols-1 row-cols-md-2 row-cols-lg-3">
{% for row in rows %}
  {%
    set row_classes = (
      default_row_class ? 'views-row col',
    )
  %}
  <div{{ row.attributes.addClass(row_classes) }}>
    {{ row.content }}
  </div>
{% endfor %}
</div>

But now I see that I must dynamically pass the classes to the template to allow different layouts (“row-cols-1 row-cols-md-2 row-cols-lg-3” or only “row-cols-1 row-cols-md-2” for example).

I saw that we can use the include twig statement with the “with” keyword, so I tried to implement the following :

real template :

{%
  set classes = (
    "card-view",
    "row",
    "row-cols-1",
    "row-cols-md-2",
  )
%}
{% include '@my_theme/views/views-view-unformatted--card-template.html.twig' with {'card_view_classes': classes} %}

and the generic template :

{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
<div{{ attributes.addClass(card_view_classes) }}>
{% for row in rows %}
  {%
    set row_classes = (
      default_row_class ? 'views-row col',
    )
  %}
  <div{{ row.attributes.addClass(row_classes) }}>
    {{ row.content }}
  </div>
{% endfor %}
</div>

But it don’t work. No classes are added.

Maybe someone can point me how to achieve this build ? Or maybe it’s not possible to do it like this ?

Thanks in advance for any answer.