Insert value in foreach loop


#1

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}}

#2

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!)


#3

Love it! Thank you