stencilproject/Stencil

Variables in for/block tags fail to render

drmidnight opened this issue · 2 comments

I'd like to nest variables in tags, however doing so causes the page to not render.

Examples

ex1:
{% for type in types %}
    {% for file in {{type}} %}
      {% include "example.stencil" %}
    {% endfor %}
{% endfor %}
ex2 base.stencil:
{% for type in types %}
    {% block {{type}} %}{% endblock %}
{% endfor %}

# then in another template
{% extends "base.stencil" %}
{% for type in types %}
    {% block {{type}} %} 
        {% for file in files %}
            # lots of html here
        {% endfor %}
    {% endblock %}
{% endfor %}

Both ways don't seem to work right. I need the templates for my project to be completely dynamic and "types" can be anything.
Any thoughts on a way to accomplish this?
Using 0.9.0

@drmidnight can you try to explain again what you expect? In the first example, if types will be [["A", "B"], ["C", "D"]] you expect second loop to recognise inner array and do iteration over their elements?

I'd like to nest variables in tags, however doing so causes the page to not render.

This is not possible. In your first example you should use type without {{ and }} in for tag. Your second example will not work as block tag does not resolve runtime variables. Also it's not supported to define blocks in a loop.