Pass variable into include I have a snippet within a template which I want to pass a variable into:

page.twig

{% set lightswitchTest = entry.aktivesProjekt('1').find() %}

{% include '_snippets/thingy' %}


thingy.twig

&lt;div class="panel{% if lightswitchTest == null %} notActive{% endif %}"&gt;
   {# bla bla #}
&lt;/div&gt;


I tried to add pass in the variable with the with keyword but I guess my syntax is wrong?

{% include '_snippets/thingy' with lightswitchTest %}


If i use the varibale now in the snippet there is just the Array to string conversion error.

What am I missing? Is there a better way?
You can leave the with lightswitchTest part off altogether, and all the variables from the parent template will be available inside the include too.

with expects an array, where the keys correspond to the variable names and their values, so if you did want to explicitly pass that in (say as a different variable) you could use:

page.twig

{% include "_snippets/thingy" with { active: lightswitchTest } %}


thingy.twig

&lt;div class="panel{% if not active %} notActive{% endif %}"&gt;
    {# bla bla #}
&lt;/div&gt;