Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Implement dynamic {% include %} tags. #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jonathanverner
Copy link

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.

  {% for year in 2014,2015,2016 %}
      {% include 'summary-{year}.html' %}
  {% endfor %}
@speedmax
Copy link
Owner

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 %}

@jonathanverner
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants