Hello team,
I was looking at the HUBL documentation and was looking for a way to find the index of all blog posts and insert a newsletter module after the 2nd post. And after that, the rest of the recent blogs will appear. How can I create an array or list of blog feed so that I can inject the newsletter column like the design below?
Hey @PYoganathan,
You can try using something like the below using loop.index. Let me know if this works for you or if you’re lookign for another solution
{% for content in contents %}
{% if loop.index == 1 %}
/*==== Your First Post Content ====*/
{% endif %}
{% endfor %}
/*==== Your Newsletter Module Content ====*/
{% for content in contents %}
{% if loop.index > 2 %}
/*=== The rest of your Post listing Content ====*/
{% endif %}
{% endfor %}
Thank you @jonchim! This solution worked. Although the newsletter is appearing after the 1st post on the listing. I assume it’s just a matter of changing the values of the if statement loop index to get it to appear after the 2nd post.
Awesome @PYoganathan! ahh read your post wrong so instead of loop.index == 1 you can do
{% if loop.index == 1 or loop.index == 2 %}
and then
{% if loop.index > 3 %}
