Can closest only be used when the lower level blocks have a setting of the same type? #76
Replies: 2 comments 5 replies
-
|
Thank you for bringing this to our attention. Today {{ closest. }} can only be used as setting configuration. We'll update the docs to reflect this we are going to address this in the new year |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for calling this out! {% schema %}
{
"name": "Card",
"blocks": [{"type": "@theme"}],
"presets": [
{
"name": "Product Card",
"blocks": [
{
"type": "group",
"blocks": [
{
"type": "text",
"settings": {
"text": "<p>{{ closest.product.title }}</p>"
}
},
{
"type": "price",
"settings": {
"product": "{{ closest.product }}"
}
},
{
"type": "product-medias",
"settings": {
"product": "{{ closest.product }}"
}
}
]
}
]
}
]
}
{% endschema %}That being said, in the coming weeks, the team will look into this further. Feel free to share with us more use cases regarding why you need Also, I wanted to clarify, by looking at the snippet you provided It seems that you are forcing forcing <ul class="product-grid">
{% for product in block.settings.collection.products %}
<li>
{% content_for "block", type: "product-card", id: "card", closest.product: product %}
</li>
{% endfor %}
</ul> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is the
closestonly available on blocks that have a setting with the same type?For eg,
I have a section that looks like this;
I have tried to pass the section collection into the
_product-gridand_section-headerblocks, however in those blocks, if I try{{ closest.collection.title }} -- {{ collection.title }}, neither of these return anything.Or am I missing something? I wouldn't expect the
collectionsetting to be required on every block that needs access to it.Also in the docs - https://shopify.dev/docs/storefronts/themes/architecture/blocks/theme-blocks/dynamic-sources#accessing-the-closest-resource, it says:
I'm assuming a leftover that was missed, before the change to
closest?Beta Was this translation helpful? Give feedback.
All reactions