include.param作为site.tags.Foo中的Foo

时间:2015-01-09 19:18:31

标签: jekyll liquid

我在_includes/last_two_foo_posts.html中使用以下代码显示最后两个标有“Foo”标签的Jekyll帖子的title

{% assign posts = site.tags.Foo %}
{% for post in posts limit:2 %}
  {{ post.title }}
{% endfor %}

我想重构代码,以便我可以使用

调用include
{% include last_two_posts.html param="Foo" %}

Liquid是否有办法在{{ include.param }}代码中为Foo使用site.tags.Foo之类的内容?

1 个答案:

答案 0 :(得分:1)

_includes / post_by_tag.html

{% assign posts = site.tags.[include.tag] %}
{% for post in posts limit: include.number %}
  <p>{{ post.title }}</p>
{% endfor %}

使用它

{% include post_by_tag.html tag='Rails' number=3 %}

Et hop!