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

variables in include tag with liquid filters #1841

Merged
merged 4 commits into from Dec 26, 2013

Conversation

Projects
None yet
5 participants
@jens-na

jens-na commented Dec 17, 2013

Use variable {% include %} with filters
This pull request adds support for filters when using the include tag with a variable.
To be more precise:

Since PR #1495 it is possible to use variables inside an include tag, like that:

    {% for item in page.dependencies %}
        {% include {{item}} %}
    {% endfor %}

but unfortunately you cannot use filters.

With this pull reuqest you can use something like this:

    {% for item in page.dependencies %}
        {% include {{ item | append: '.html' }} %}
    {% endfor %}

This is especially useful when you want to modify the file/filename which should get included.

Possible use cases

Append .html to the file name

{% include {{ item | append: '.html' }} %}

Make sure the file name is lowercase

{% include {{ item | downcase | append: '.html' }} %}

Prepend a directory to choose another directory inside the _includes/ directory

{% include {{ item | downcase | prepend: '/dependencies/' | append: '.html' }} %}
==> ./_includes/dependencies/<item>.html
@coveralls

This comment has been minimized.

Show comment
Hide comment
@coveralls

coveralls Dec 17, 2013

Coverage Status

Coverage remained the same when pulling 43ef9a2 on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

coveralls commented Dec 17, 2013

Coverage Status

Coverage remained the same when pulling 43ef9a2 on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr
Member

parkr commented Dec 17, 2013

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Dec 18, 2013

Contributor

Looks great! Just the one comment above.

Contributor

maul-esel commented Dec 18, 2013

Looks great! Just the one comment above.

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Dec 18, 2013

Contributor

Oh and also, as we discussed in #1789, this fixes cases like {% include {{ var }} %} (spaces inside brackets), so you might wanna remove the note concerning this from the docs (here or in a separate PR / commit once this is merged).

Contributor

maul-esel commented Dec 18, 2013

Oh and also, as we discussed in #1789, this fixes cases like {% include {{ var }} %} (spaces inside brackets), so you might wanna remove the note concerning this from the docs (here or in a separate PR / commit once this is merged).

@coveralls

This comment has been minimized.

Show comment
Hide comment
@coveralls

coveralls Dec 19, 2013

Coverage Status

Coverage increased (+0.42%) when pulling 412fe8b on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

coveralls commented Dec 19, 2013

Coverage Status

Coverage increased (+0.42%) when pulling 412fe8b on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Dec 19, 2013

Contributor

👍

Contributor

maul-esel commented Dec 19, 2013

👍

@coveralls

This comment has been minimized.

Show comment
Hide comment
@coveralls

coveralls Dec 19, 2013

Coverage Status

Coverage increased (+0.24%) when pulling 412fe8b on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

coveralls commented Dec 19, 2013

Coverage Status

Coverage increased (+0.24%) when pulling 412fe8b on jens-na:include-variable-liquid-filters into 12a55b8 on jekyll:master.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Dec 19, 2013

Member

Looking great! Would you please add a test for multiple filters so we know that one works, too? :)

Member

parkr commented Dec 19, 2013

Looking great! Would you please add a test for multiple filters so we know that one works, too? :)

@jens-na

This comment has been minimized.

Show comment
Hide comment
@jens-na

jens-na Dec 19, 2013

Do you mean a cucumber test?
I have already added several tests in test/test_tags.rb (including a test for multiple filters)

Specifically I test something like this:

---
include3: INCLUDE
---
{% include {{ page.include3 | downcase | append: '.html' }} %}

jens-na commented Dec 19, 2013

Do you mean a cucumber test?
I have already added several tests in test/test_tags.rb (including a test for multiple filters)

Specifically I test something like this:

---
include3: INCLUDE
---
{% include {{ page.include3 | downcase | append: '.html' }} %}
@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Dec 19, 2013

Member

Indeed! Thanks.

This LGTM. @mattr-?

Member

parkr commented Dec 19, 2013

Indeed! Thanks.

This LGTM. @mattr-?

@parkr parkr merged commit 6e8f31f into jekyll:master Dec 26, 2013

1 check passed

default The Travis CI build passed
Details

parkr added a commit that referenced this pull request Dec 26, 2013

@jens-na jens-na referenced this pull request Mar 15, 2014

Merged

Variable {% include %} #1495

4 of 4 tasks complete

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.