Hi! I like to know if the post offset is possible in ghost, and if it is, then how? Like when I get first five posts, I like to add a CTA between and then continue the posts from the sixth ( first five above the cta, and continue from the sixth post after the CTA).
PLEASE HELP!
Hey @andy01,
You’d might like to use limit
and from
attribute of {{#foreach}}
helper to achieve this. More info here.
{{#get "posts"}}
{{#foreach posts limit="5"}}
...
{{/foreach}}
CTA
{{#foreach from="6"}}
...
{{/foreach}}
{{/get}}
Or you could also use a combination of {{#has}}
helper and number
data variable inside the loop. More info here.
{{#foreach posts}}
{{#has number="6"}}
CTA
{{/has}}
...
{{/foreach}}
Thank you @minimaluminium , since I am new to the Ghost Platform, I was confused about the concepts in Theme Development documentation. But can you please explain the difference between {{#foreach}}
helper and the {{#has}}
helper, like when to use which?
Those helpers are different from each other and one doesn’t replace the another. The both solutions above use {{#foreach}}
helper.
{{#foreach}} - Loop helper which is used for iterate over a list of posts
{{#has}} - This is similar to {{#if}} helper which allows testing conditionals. The difference is it can test more than boolean, number
data variable in this case.
Oh, I get it now, Thanks for you help!