You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Other platforms and frameworks have the ability to place code within a placeholder element somewhere else on the theme.
October CMS does this using {% placeholder xyz %}, Astro does this using <slot name="xyz" />.
It makes sense for Shopify to allow this due to the hugely dynamic nature of sections and blocks.
Right now, to include dynamic styles on a section, I need to write them within the section file, which means the style and script definitions are littered everywhere.
A Liquid slot tag would allow developers to better optimise their themes by allowing specific blocks of code to go in specific areas.
yield? content_for? a couple patterns from rails-land that feel related
benjaminsehl
changed the title
Request for suggestions: Liquid slot tag to render contents in predefined places
Request for improvements: Liquid slot tag to render contents in predefined places
Dec 11, 2024
Slot is a long needed feature in Liquid. I've actually raised the idea back in 2022 (#1530) and actually for even longer in a old private GitHub repo targetted at theme partners.
Now that theme blocks have landed, this gave me some more ideas for syntax. Snippets are now nearly equivalent to theme blocks, so I think it would make sense to extend snippets to give them some unique power, slot being the perfect use case.
As @isaacbowen , I think the correct syntax would be to use content_for to align that with theme blocks:
This make the whole thing consistent with how theme block and static theme blocks work.
There are a few open questions:
Default slots
Shadow DOM for instance allows a default slot. I think that for simplicity and to prevent introducing too much surface syntax, we should limit to named slots only.
Syntax for checking if empty
In this example I have captured the slot content to output conditionally the header. This avoids creating another syntax, while still allowing to do it with an extra capture.
Other platforms and frameworks have the ability to place code within a placeholder element somewhere else on the theme.
October CMS does this using
{% placeholder xyz %}
, Astro does this using<slot name="xyz" />
.It makes sense for Shopify to allow this due to the hugely dynamic nature of sections and blocks.
Right now, to include dynamic styles on a section, I need to write them within the section file, which means the style and script definitions are littered everywhere.
A Liquid
slot
tag would allow developers to better optimise their themes by allowing specific blocks of code to go in specific areas.Examples
Styles
slider.liquid
The text was updated successfully, but these errors were encountered: