So I have a recipes blog and I wanted each blogpost template to have a custom block under blog page section that is a grid card layout pretty much exactly how the featured collection section works. This is to link the products used in that recipe to the products page in my shop, and allow for customers to easily add the product (s) to cart without needing to back out and search for said product. It works, but the look of it is strange and for somereason the first iteration of the for loop does not classify the first product in the array as a
Here is my code, any help is greatly appreciated!
<article class="article-template">
{%- for block in section.blocks -%}
{%- case block.type -%}
{%- when 'related_products' -%}
{% if article.metafields.product_info.related_products %}
{% assign relatedproducts = article.metafields.product_info.related_products.value %}
<p
class="related-products-heading"
style="font-size: {{block.settings.heading_font_size}}px;
color: {{block.settings.heading_color}};"
>
{{ block.settings.heading }}
</p>
<div class= "product-grid-container"
id="ProductGridContainer"
>
<div class="related-products page-width">
<div class="loading-overlay gradient"></div>
<ul
id="product-grid"
data-id="{{ section.id }}"
class="grid product-grid grid--{{ section.settings.columns_mobile }}-col-tablet-down
grid--{{ section.settings.columns_desktop }}-col-desktop
{% if section.settings.quick_add == 'bulk' %} collection-quick-add-bulk{% endif %}"
{% for prod in relatedproducts %}
<li
class="grid__item"
>
{% render 'card-product',
card_product: prod,
media_aspect_ratio: section.settings.image_ratio,
image_shape: section.settings.image_shape,
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
quick_add: block.settings.quick_add,
section_id: section.id
%}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}