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 &quot;card&quot; 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 %}
  &lt;h3&gt;{{ title }}&lt;/h3&gt;
{% endif %}
&lt;div class=&quot;card-view row row-cols-1 row-cols-md-2 row-cols-lg-3&quot;&gt;
{% for row in rows %}
  {%
    set row_classes = [
      default_row_class ? 'views-row col',
    ]
  %}
  &lt;div{{ row.attributes.addClass(row_classes) }}&gt;
    {{ row.content }}
  &lt;/div&gt;
{% endfor %}
&lt;/div&gt;


But now I see that I must dynamically pass the classes to the template to allow different layouts (&quot;row-cols-1 row-cols-md-2 row-cols-lg-3&quot; or only &quot;row-cols-1 row-cols-md-2&quot; for example).
I saw that we can use the include twig statement with the &quot;with&quot; keyword, so I tried to implement the following :
real template :
{%
  set classes = [
    &quot;card-view&quot;,
    &quot;row&quot;,
    &quot;row-cols-1&quot;,
    &quot;row-cols-md-2&quot;,
  ]
%}
{% include '@my_theme/views/views-view-unformatted--card-template.html.twig' with {'card_view_classes': classes} %}

and the generic template :
{% if title %}
  &lt;h3&gt;{{ title }}&lt;/h3&gt;
{% endif %}
&lt;div{{ attributes.addClass(card_view_classes) }}&gt;
{% for row in rows %}
  {%
    set row_classes = [
      default_row_class ? 'views-row col',
    ]
  %}
  &lt;div{{ row.attributes.addClass(row_classes) }}&gt;
    {{ row.content }}
  &lt;/div&gt;
{% endfor %}
&lt;/div&gt;

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.
Yes @Clive, it's correct. I can simply declare a variable called &quot;card_classes&quot; and it is passed to the sub-template. During my tests I targeted an incorrect base template. It was my problem :-/
In the included template :
{% if card_classes is not defined %}
  {% set card_classes = [
    'card-view',
    'row',
    'row-cols-1',
    'row-cols-md-2',
    'row-cols-lg-3',
    ]
  %}
{% endif %}

{% if title %}
  &lt;h3&gt;{{ title }}&lt;/h3&gt;
{% endif %}
&lt;div{{ attributes.addClass(card_classes)}}&gt;
{% for row in rows %}
  {%
    set row_classes = [
      default_row_class ? 'views-row col',
    ]
  %}
  &lt;div{{ row.attributes.addClass(row_classes) }}&gt;
    {{ row.content }}
  &lt;/div&gt;
{% endfor %}
&lt;/div&gt;

By checking if card_classes variable is defined or not, I can set default classes in the included template itself, or override the default classes in the base template.
And now in base templates :
{# use default classes #}
{{ include('@my_theme/views/views-view-unformatted--card-template.html.twig') }}

or to override
{# override default classes by another set of classes #}
{%
  set card_classes = [
    'card-view',
    'row',
    'row-cols-1',
    'row-cols-md-2'
  ]
%}

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