Hello Shopify Devs,
In Shopify, before adding a section, there’s a visual preview. Recently I noticed that in this preview, my custom built sections are broken, because {{ section.id }}
includes invalid characters which break the section.
Example:
{% style %}
.section#section_{{ section.id }} {
--text-color: red;
}
{% endstyle %}
<div class="section" id="section_{{ section.id }}">
<h2 style="color: var(--text-color)">Hello there</h2> // text is not red
</div>
everywhere besides the visual preview, {{ section.id }}
looks like:
section_template--25013359542583__abcd
This is valid and works fine for the id
attribute.
However, In visual preview, {{ section.id }}
looks like:
section_template--25013359640887__eyJzZWN0aW9uIjoiYWRldi1pbWFnZS13aXRoLXRleHQtdjIiLCJzaWduYXR1cmUiOiJOZXcgSW1hZ2Ugd2l0aCBUZXh0IFYyIn0=
This contains =
, which is not valid in an HTML id
which breaks the section styles and javascript that use the section.id
Hope this can be fixed asap.