Filter product collection loop with featured products and custom frontmatter

As mentioned in the previous answer, the solution to avoid duplication is by using includes to render every section after the featured product.
To facilitate easier maintenance, you need to merge your _products collection and products data file into one of either type — either collection of product documents or a folder of individual data files. (Yes, _data/products/product_a.yml, _data/products/product_b.yml, etc) is perfectly valid.


Since your posts need to be rendered in the ratio of 1:4:6, make sure you have configured the site to paginate posts by 11 items.

Then use {% assign --- %} tag and slice filter to manipulate the list of posts.

## Sticky Post
### {{ paginator.posts[0].title }}

## Featured Posts
{% assign featured_posts = paginator.posts | slice: 1, 4 %}
{% for post in featured_posts %}
### {{ post.title }}
{% endfor %}

## More products
{% assign rest = paginator.posts | slice: 5, 6 %}
{% for post in rest %}
### {{ post.title }}
{% endfor %}

Move the forloops to includes if you don’t want duplication.

2 Likes