gpt4 book ai didi

concatenation - jekyll 在循环中分配 concat?

转载 作者:行者123 更新时间:2023-12-04 03:14:20 25 4
gpt4 key购买 nike

我想根据通过过滤器的页面数量来组织页面。

我曾尝试将 truthy 页面附加到集合中,但它不起作用。

{% assign homepage_posts = [] %}
{% for my_page in site.pages %}
{% if my_page.homepage %}
{% assign homepage_posts = homepage_posts | concat: [my_page] %}
{% endif %}
{% endfor %}

<h1>size{{homepage_posts.size}}</h1>
<h1>{{homepage_posts}}</h1>

这是行不通的。 concat 只适用于字符串吗?

最佳答案

Jekyll 很快就会使用 Liquid 4。但是,目前还没有 concat

在您的情况下,您可以:

创建一个空数组(括号符号在 liquid 中不起作用):{% assign homepage_posts = ""|拆分:"/"%}

{{ homepage_posts |检查 }} --> 输出:[]

并将元素压入其中:

{% for my_page in site.pages %}
{% if my_page.homepage %}
{% assign homepage_posts = homepage_posts | push: mypage %}
{% endif %}
{% endfor %}

{{ homepage_posts | inspect }}

关于concatenation - jekyll 在循环中分配 concat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42475187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com