liquid icon indicating copy to clipboard operation
liquid copied to clipboard

assign behavior

Open zhuzhonghua opened this issue 14 years ago • 4 comments

when i wrote, {{site.pages | sort: "date"}},i had the right order.

then i wrote, {% assign page_list = site.pages | sort:"date" %}, no effect.

i am using jekyll-bootstrap, downloaded from github

zhuzhonghua avatar Oct 25 '12 13:10 zhuzhonghua

I believe that when you use filters inside a Liquid tag ({% sometag %}) you have to remove the spaces in the filter expression. So, your code would become this:

{% assign page_list = site.pages|sort:"date" %}

nickpearson avatar Oct 25 '12 13:10 nickpearson

I'm sorry,it's no use.

Actually, my code is like this:

{% for tag in site.tags %} {% if tag[0] == "xxx" %}

    {% assign pages_list= tag[1]|sort:"date" %} {% include JB/pages_list %}
{% endif %} {% endfor %}

I got the reverse order.

Currently, I am using:

JB/reverse_pages_list ,it's like this:

{% for item in pages_list reversed %} xxx {% endfor %}

zhuzhonghua avatar Oct 27 '12 09:10 zhuzhonghua

@zhuzhonghua i did not quite get your last comment, but i think that @nickpearson is right.

have a look at this example:

template = Liquid::Template.parse("
{% assign p = products | sort %}
{% for product in p %} {{ product }} {% endfor %}
")
template.render('products' => ['zzzz', 'aaaa'] )
# => aaaa  zzzz

phoet avatar Jun 09 '13 13:06 phoet

Closing. Please re-open if this is still an issue.

fw42 avatar Jul 22 '13 19:07 fw42