Jekyll Liquid语法,如何取消对属性的引用
我正在使用这个液体标签对我网站上的帖子进行分组Jekyll Liquid语法,如何取消对属性的引用,jekyll,liquid,Jekyll,Liquid,我正在使用这个液体标签对我网站上的帖子进行分组 {% assign postsForYear = site.posts | group_by_exp:"post", "post.date | date: '%Y'" | where: "name", "2020" %} 当我将postForYear返回到屏幕时,我看到: {"name"=>"2020", "
{% assign postsForYear = site.posts | group_by_exp:"post", "post.date | date: '%Y'" | where: "name", "2020" %}
当我将postForYear
返回到屏幕时,我看到:
{"name"=>"2020", "items"=>[#, #, #, #, #, #], "size"=>6} 0
这是有道理的,因为那一年我有六个职位。但是,我正在尝试取消对该对象的引用,并获取可以在输出中看到的.size
属性…我无法理解语法
如何获取.Size属性?
这些都不管用
{{ postsForYear.size }}
{{ postsForYear.items | size }}
在那之后,我很想学习如何在帖子中找到自己的路……这看起来也很简单,但不管用 啊,我知道了。奇怪的是,
postsForYear
数组实际上被视为数组本身,因此我必须索引到第一个位置才能获得属性
{% assign postsForYear = site.posts |
group_by_exp:"post", "post.date | date: '%Y'" | where: "name", "2020" %}
###doesn't work
{{ postsForYear.items | size }}
##works
Posts for year {{ postsForYear[0].name }}, total posts {{ postsForYear[0].size }}
>Posts for year 2020, total posts 6
回答我的另一个问题,如何通过:
{% for post in postsForYear[0].items %}
<h1>{{post.title}}</h1><br>
{% endfor %}
{postsForYear[0]中的post的百分比。items%}
{{post.title}}
{%endfor%}
对于记录,数组是由
组创建的,如文档所示:{site.members}组创建的exp:“item”,“item.gradication|u year | truncate:3,”}
将给出类似于[{“name”=>“201”,“items”=>[…],{“name”=>“200”,“items”=>[…]的内容。
啊,有意义。非常感谢。这意味着我真的不明白你们为什么这么做。您可以这样做:其中:“post”,“post.date | date:“%Y'==2020”
(或者==2020'
,可能是因为我希望date返回字符串)