jekyll / jekyll-help

NO LONGER MAINTAINED. USE JEKYLL TALK INSTEAD.
https://talk.jekyllrb.com
146 stars 19 forks source link

Liquid assign tag and filters #257

Closed maiertech closed 9 years ago

maiertech commented 9 years ago

I have a collection classification. In a template I want to read one item from the collection based on a front matter id value.

I thought this is straightforward. But then I noticed (using the Octopress debugger) that after executing

{% assign item = site.classification | where:"id","xyz" %}
{% debug %}

item contains a flattened String representation of the collection item and not the collection item itself (as I would have expected). I noticed the same for the group_by filter. It seems that the assign tag in conjunction with these filter flattens the result to a String. It does not seem to be the filter itself. Jekyll's where filter seems fine when I look at the source code.

When I do

{% assign item = site.classification %}
{% debug %}

without filter, the debugger shows me that item contains the actual collection as it should.

What is the expected behavior when applying the filters mentioned here: http://jekyllrb.com/docs/templates/?

maiertech commented 9 years ago

Just read in Liquid docs that filters can be applied only to output tags {{ }}. Is there any way to select a subset from a collection other than iterating through the collection with a for loop?

doktorbro commented 9 years ago

Try the where filter.

parkr commented 9 years ago

This repository is no longer maintained. Please search for your issue on Jekyll Talk, our new community forum. If it isn't there, feel free to post to the Help category and someone will assist you. Thanks!