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


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

{% include '_snippets/thingy' %}


<div class="panel{% if lightswitchTest == null %} notActive{% endif %}">
   {# bla bla #}

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?

1 Answer 1


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:


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


<div class="panel{% if not active %} notActive{% endif %}">
    {# bla bla #}
  • 3
    It's also possible to pass the only parameter, if you want to exclude other variables from being exposed to the included template: {% include "_snippets/thingy" with { active: lightswitchTest } only %} Commented Oct 24, 2016 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.