Replies: 6 comments 10 replies
-
|
Hey @bakura10, you can actually opt out of having a wrapping element by adding Unless I'm misunderstanding and you had done that already 🤔 |
Beta Was this translation helpful? Give feedback.
-
|
Ah yeah I miss this. But this should then be the default as I will basically need to do that for all blocks. I think Shopify could abstract it and keep the wrapper (the wrapper has the benefit that you don’t have to output block.shopify_attributes yourself) but do not output the wrapper if nothing is rendered in the block |
Beta Was this translation helpful? Give feedback.
-
|
Another perspective here -- what I feel like this overlaps with is how sections/blocks/themes handle placeholder content, ie. what gets rendered when the intended content is not set. Maybe a pattern that could be defined here to handle this case + all other placeholder content cases? |
Beta Was this translation helpful? Give feedback.
-
|
Is there some progress on this issue @ludoboludo I'm doing some more experiments and this is actually a huge problem and I'm not sure how to solve this cleanly. Even if the content is empty, Shopify generate an empty string, which prevents to use the :empty CSS selector.
But, ideally, Shopify should check if the content is empty and, if it is, completely remove the parent from the DOM. For now, the only workaround I found would be to use the following CSS: This would ensure that block are ignored in the DOM tree, but I'm afraid this might cause compatibility issue with some apps. |
Beta Was this translation helpful? Give feedback.
-
@bakura10 this should now be fixed, we shipped a fix for this bug yesterday. |
Beta Was this translation helpful? Give feedback.
-
|
This is an interesting idea — I don’t know how I feel about it. I get what you mean, basically “don’t let the merchant ship an empty block that they don’t intend to be there… and don’t force me to do defensive coding for it” … will think more about it. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hi :),
As of today, if a block does not output anything, it will still output in the DOM the wrapper:
Especially with settings bounded to metafields that might be empty, this will generate a lot of empty DOM elements:
We often use the sibling selector in CSS, and this basically breaks it.
Beta Was this translation helpful? Give feedback.
All reactions