【发布时间】:2016-01-15 15:19:39
【问题描述】:
也许这是一个 Python 程序员尝试使用 Ruby 的案例,也许这是 "feature"——我不知道。对于我的生活,我无法弄清楚如何在渲染过程中设置帖子的状态。
我有一个_layout,它只调用了两次include:
{% include templateA %}
{% include templateB %}
templateA 在some_condition 的基础上遍历帖子并渲染一些。
{% for post in site.posts %}
{% if some_condition %}
<!-- Render the post -->
{% assign post.rendered = true %}
{% endif %}
{% endfor %}
templateB 尝试遍历帖子并渲染其余部分:
{% for post in site.posts %}
{% unless post.rendered %}
<!-- Render the post -->
{% endif %}
{% endfor %}
这没有按预期工作。我也尝试过{% assign post[rendered] = true %} 语法。没有错误被抛出;只是无声的失败。
我在哪里失败了?我对渲染过程的心理模型完全错误吗?谢谢!
【问题讨论】:
-
我不知道 jekyll 的内部结构。也许包含不按顺序运行,或者变量赋值不传播。在 templateB 中再次检查
some_condition怎么样? -
是的,这就是备用计划。不过,它的封装很差。