【问题标题】:How to iterate through posts and make groups in Ghost如何在 Ghost 中遍历帖子并创建群组
【发布时间】:2020-03-13 16:40:58
【问题描述】:

各位鬼作家们好,

我基本上是在基于 Bootstrap 开发自己的主题。因此,我想创建一个文章链接的轮播。我展示了 3 张引导卡,我想添加一个旋转木马。 这相当容易,因为我只需要制作一个卡组旋转木马并在每个卡组中放 3 张卡。

但是,有一个问题......我如何告诉 Ghost 遍历所有帖子并创建三个帖子的“组”?换一种说法:“foreach 帖子和每 3 个帖子都...”

其实我有:

        {{#foreach posts limit="3"}}
            {{> "post-card"}}
        {{/foreach}}

我需要类似的东西:

        {{#foreach posts}}
            {{every 3 items}}
                <div class="card-deck">
                    {{> "post-card"}}
                </div>
        {{/foreach}}

我真的不知道如何开始。

问候

【问题讨论】:

    标签: twitter-bootstrap bootstrap-4 handlebars.js ghost-blog


    【解决方案1】:

    这可以在#foreach 循环上设置columns 值时使用@rowStart@rowEnd 来完成。这是一个例子:

    {{#foreach posts columns="3"}}
        {{#if @rowStart}}<div class="card-deck">{{/if}}
            {{> "post-card"}}
        {{#if @rowEnd}}</div>{{/if}}
    {{/foreach}}
    

    通过将columns 设置为3 @rowStart 将表示列的开始,@rowEnd 将表示列的结束。

    更多信息可以在 Ghost 车把文档中找到:https://ghost.org/docs/api/v3/handlebars-themes/helpers/foreach/#data-variables

    希望这会有所帮助!

    【讨论】:

    • 非常感谢。我浏览了 ghost 和车把的文档,但错过了。它有效
    猜你喜欢
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 2021-04-18
    • 2018-07-17
    • 1970-01-01
    • 2022-06-19
    • 1970-01-01
    相关资源
    最近更新 更多