Hi there,
I am trying to find a way to inject a preview of a collection of products within several blog posts of my website. I use the Impulse 7.2 theme. The collection preview (aka featured collection) can be different depending on the blog post.
I followed the tutorial here https://thefunction.works/how-to-add-product-blocks-inside-your-blog-using-nothing-but-liquid-shopify/
And instead of referring to individual product handles, I would like instead to refer to collection handles.
So here the code I inserted inside article-template.liquid
{% assign divider = '[COLLECTION]' %}
{% assign dividerClose = '[/COLLECTION]' %}
{% assign text = article.content | split: divider %}
{{ text[0] }}
{% for divider in text offset:1 %}
{% assign x = forloop.index %}
{% assign newtext = text[x] | split: dividerClose %}
{% assign collectionHandle = newtext[0] %}
{% assign collection = collections[collectionHandle] %}
{% if collection.products.size > 0 %}
#### {{ collection.title | escape }}
{% endif %}
{% for product in collection.products limit: 3 %}
{% include 'product-grid-item' %}
{% else %}
{% for i in (1..product_limit) %}
{% include 'product-grid-item' %}
{% endfor %}
{% endfor %}
{{ newtext[1] }}
{% endfor %}
As you can see i have replaced PROD by COLLECTION and will be using the Collection handle as an input inside the blog.
What i would like to do is to replace the rendering of the collection shown below
{% for product in collection.products limit: 3 %}
{% include 'product-grid-item' %}
{% else %}
{% for i in (1..product_limit) %}
{% include 'product-grid-item' %}
{% endfor %}
{% endfor %}
with the proper Impulse featured collection “section” that is used here and there on my website including the homepage. Here is an example:
I’m new to liquid programming, i did find the section called “featured-collection.liquid” but i couldn’t find a way to render such section within the article-template.liquid. Even by using the render function instead of include.
It seems that it is not possible to render a section within another section. And instead i should be rendering snippets. Is there a snippet that includes all the logic of the featured collection of the Impulse theme as shown on the screenshot ?
Thanks a lot for your support!
Marc
