Liquid 机车CMS:动态,内容类型模板页面上有范围过滤器?

Liquid 机车CMS:动态,内容类型模板页面上有范围过滤器?,liquid,locomotivecms,Liquid,Locomotivecms,我在一个机车CMS网站上工作,正在寻找一种按类别动态列出帖子的方法 例如,我有两个数据模型:Posts和Category Posts数据模型具有与类别关联的“属于”属性。我还有一个类别的模板化视图 我想做一些类似的事情: {% with_scope category: category._slug %} {% for post in contents.post %} {{post.title}} {% endfor %} {% endwith_scope %}

我在一个机车CMS网站上工作,正在寻找一种按类别动态列出帖子的方法

例如,我有两个数据模型:Posts和Category

Posts数据模型具有与类别关联的“属于”属性。我还有一个类别的模板化视图

我想做一些类似的事情:

{% with_scope category: category._slug %}
    {% for post in contents.post %}
        {{post.title}}
    {% endfor %}
{% endwith_scope %}
在模板化的分类页面上,但到目前为止,它没有返回任何结果,即使有带有这些分类的帖子


有什么想法吗?谢谢大家!

我在试图解决这个问题的过程中也发现了这个悬而未决的问题

以下是一个解决方案:

// Iterate through all categories
{% for category in contents.categories %}

    // Assign the current iteration category to a variable
    {% assign loopCategory = category %}

    // with_scope the current iteration category
    {% with_scope category: loopCategory %}

        // Check if this category has been assigned to any content entries (posts, or 
        whatever else you might be classifying)
        {% if contents.posts != empty %}

            {% for post in contents.posts %}

                // display your post / content entry info

            {% endfor %}

        {% else %}

        {% endif %}

    {% endwith_scope %}

{% endfor %}

这将在标准页面上工作。我预计模板化页面可能会有更多问题,但我也需要实现这一点,以便在找到解决方案时更新我的答案。

快速问题:您有两个数据模型:“帖子”和“类别”。您是否将类别内容类型设置为单数或复数?我还注意到,在您的代码中,您在contents.post%}中为post添加了
{%。我的理解是,这样您就可以在contents.categories%}
中使用
{%for category in contents.posts%}
{%for post in contents.posts%}。我想如果你对内容中的[singular].[singular]}
执行
{%操作,系统可能会混淆。