Insert value in foreach loop

Hi, I would like to insert a content with handlebars in a foreach loop.
Specifically, I would like to insert an item in the list of articles after the first three
How to solve the problem?

This is an example of code:

{{#get "posts"  include="tags" limit="6"}}
<div class="post-feed">
    {{#foreach posts}}
    {{> "post-card"}}
    {{/foreach}}
</div>  
{{/get}}

I would like to do something like this. Es:

{{#get "posts"  include="tags" limit="6"}}
<div class="post-feed">
    {{#foreach posts}}
    {{> "post-card"}}

   every_three_posts {
   <p>Hello World!</p>
   }

    {{/foreach}}
</div>  
{{/get}}

You need the has helper

{{#get "posts"  include="tags" limit="6"}}
<div class="post-feed">
    {{#foreach posts}}
    {{> "post-card"}}
    {{#has index="nth:3"}}
        this will show up every third post!
    {{/has}}
    {{/foreach}}
</div>  
{{/get}}

(all credit for this implementation goes to @Hannah!)

1 Like

Love it! Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.