[英]How to iterate through posts and make groups in Ghost
Hello fellow ghost writers,各位幽灵作家,大家好,
I am basically developping my own theme based on Bootstrap.我基本上是基于 Bootstrap 开发我自己的主题。 Therefore I want to create a carousel of links to article.因此,我想创建一个指向文章的链接轮播。 I display 3 Bootstraps cards and I would like to add a caroussel.我展示了 3 张 Bootstraps 卡片,我想添加一个旋转木马。 It is fairly easy as I just need to make a caroussel of card decks and put 3 cards per card deck.这相当简单,因为我只需要制作一副纸牌旋转木马并在每副纸牌中放 3 张牌。
But, there is a problem... How I tell Ghost to iterate through all posts and create "groups" of three posts ?但是,有一个问题......我如何告诉 Ghost 遍历所有帖子并创建三个帖子的“组”? Put differently: "foreach posts and every 3 posts do..."换种说法:“foreach 帖子和每 3 个帖子都做……”
I actually have:我实际上有:
{{#foreach posts limit="3"}}
{{> "post-card"}}
{{/foreach}}
And I need something like:我需要类似的东西:
{{#foreach posts}}
{{every 3 items}}
<div class="card-deck">
{{> "post-card"}}
</div>
{{/foreach}}
I have really no idea how to start with that.我真的不知道如何开始。
Regards问候
This can be done using @rowStart
and @rowEnd
when setting a columns
value on the #foreach
loop.这可以在#foreach
循环上设置columns
值时使用@rowStart
和@rowEnd
来完成。 Here's an example:下面是一个例子:
{{#foreach posts columns="3"}}
{{#if @rowStart}}<div class="card-deck">{{/if}}
{{> "post-card"}}
{{#if @rowEnd}}</div>{{/if}}
{{/foreach}}
By setting a columns
to 3
@rowStart
will signal the beginning of a column and @rowEnd
will signal the end of a column.通过将columns
设置为3
@rowStart
将表示列的开始, @rowEnd
将表示列的结束。
More info can be found in the Ghost handlebars docs: https://ghost.org/docs/api/v3/handlebars-themes/helpers/foreach/#data-variables更多信息可以在 Ghost 把手文档中找到: https : //ghost.org/docs/api/v3/handlebars-themes/helpers/foreach/#data-variables
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.