h2o-php icon indicating copy to clipboard operation
h2o-php copied to clipboard

Feat: Implement dynamic {% include %} tags.

Open jonathanverner opened this issue 11 years ago • 2 comments

I found it useful to be able to include different files based on the content of variables, e.g.

{% for year in 2014,2015,2016 %}
    {% include 'gallery-{year}.html' %}
{% endfor %}

This commit implements this.

jonathanverner avatar May 19 '14 22:05 jonathanverner

I am not sure if we should introduce string interpolation only on include tag, this should be rather consistent in other places.

I'd think supporting variable lookup on include tag is probably a better way to go.

{% for partial in page.partials %}
   {% include partial %}
{% endfor %}

speedmax avatar May 21 '14 11:05 speedmax

Variable lookup on the include tag would not solve the problem I had: I had a list of years (either a literal list or in a variable), but I wanted my templates to have descriptive names, e.g. gallery-2005.html, not just 2005. I could have of course constructed the names in PHP, but that seems to defeat the purpose of having a template engine.

I agree that consistency would be nice. If you decide that string interpolation is reasonable, I will try to look into that. I guess, for consistency's sake, it would also be better to have 'gallery-{{year}}.html' (i.e. double curly braces instead of single ones).

jonathanverner avatar May 21 '14 18:05 jonathanverner