Variable not expanded inside an included selmer template

180 views Asked by At

I have a top-level template where I want to use a "fragment" template inside a for cycle but I'm not able to pass in the variable value:

  {% for item in coll %}
    {% include "fragment.html" with name="slack" item=item %}
  {% endfor %}

item and name is then used in the fragment.html template:

<div>
  <label>
    <input
      title="{{item.id}}"
      id="{{name}_{{item.id}}_active"
      name="{{name}}-{{item.id}}_active"
...
    />

While the name parameter is expanded properly (its value is hardcoded in the parent template), the item parameter is not (its value is passed in as is).

Do I need to use a different syntax for that or it's just not supported?

1

There are 1 answers

3
Jeremy On

The include tag splices in the included template. This means that any variables within scope of the parent template will be available to the included template. The with operator allows you to supply default values, which are not interpreted. Saying item=item is effectively saying item|default:"item", which is to say that item is redefined as "item".

See https://github.com/yogthos/Selmer#including-templates