I’ve created a page builder that uses theme blocks, including a main section that accepts those blocks. On the product page, we’re using metafields to populate content within these blocks. I set up a section on the product page using theme blocks, but I’m running into two issues:
-
The section should be removed automatically if the block’s metafields are empty.
-
I need to loop through the metafields using theme blocks (based on the image, each element is a theme block).
Hi @Marlowe-pahlowm
try using either the available_if, or visible_if fields if those are available for your context.
Or setting the scheme to not have a container tag, and wrap the whole thing in a check condition based on variables allowed in the current scope.
no message passing ?
, sections are scoped and so are blocks, so a section can’t get a dynamic blocks settings or properties, or variable values, etc.
theme blocks are either dynamic or static, if you have to loop and define things because of that loop then it’s static theme blocks.
Otherwise each /block needs it’ own internal loop.
There’s also sidestepping by using things like html sl0ts and javascript etc but IMO that should be last resort used as a progressive enhancement.
On top of double checking the theme architecture docs for theme blocks:
https://shopify.dev/docs/storefronts/themes/architecture/blocks
Also checkout the reference theme discussions:
https://github.com/Shopify/reference-theme/discussions