I'm working on rendering Shopify themes where blocks can be nested inside sections and other blocks. Each has settings stored in a JSON file, and to load the right settings, I need to know the chain of files that led to rendering the current one.
For example, when rendering product-title.liquid ← _product-card.liquid ← main-collection.liquid, I need to navigate through nested JSON objects using these filenames as keys:
{
"sections": {
"main": {
"type": "main-collection",
"blocks": {
"product-card": {
"type": "_product-card",
"blocks": {
"product_title_4nY4eT": {
"type": "product-title",
"settings": {
"font_size": "1rem",
"color": "var(--color-foreground)",
...
}
}
}
}
}
}
}
}
Current Workaround
Right now I'm doing this by:
- Hooking into the
TemplateParsed event
- Adding custom
path tags with enter/exit flags at the beginning and end of each file
- Maintaining a stack of filenames in the model
This works, but feels hacky since Fluid already tracks file transitions internally for its own purposes.
Question
Is there a built-in way to access the current file nesting path during rendering? Something like a context property that would give me ["main-collection", "_product-card", "product-title"] when I'm inside product-title.liquid?
If not, would you be open to exposing this information? It seems like it could be useful for other scenarios where you need to know the render context (debugging, conditional logic based on parent templates, etc.).
Maybe I'm just missing something obvious? Let me know if there's already a way to do this that I haven't found!
I'm working on rendering Shopify themes where blocks can be nested inside sections and other blocks. Each has settings stored in a JSON file, and to load the right settings, I need to know the chain of files that led to rendering the current one.
For example, when rendering
product-title.liquid←_product-card.liquid←main-collection.liquid, I need to navigate through nested JSON objects using these filenames as keys:{ "sections": { "main": { "type": "main-collection", "blocks": { "product-card": { "type": "_product-card", "blocks": { "product_title_4nY4eT": { "type": "product-title", "settings": { "font_size": "1rem", "color": "var(--color-foreground)", ... } } } } } } } }Current Workaround
Right now I'm doing this by:
TemplateParsedeventpathtags withenter/exitflags at the beginning and end of each fileThis works, but feels hacky since Fluid already tracks file transitions internally for its own purposes.
Question
Is there a built-in way to access the current file nesting path during rendering? Something like a context property that would give me
["main-collection", "_product-card", "product-title"]when I'm insideproduct-title.liquid?If not, would you be open to exposing this information? It seems like it could be useful for other scenarios where you need to know the render context (debugging, conditional logic based on parent templates, etc.).
Maybe I'm just missing something obvious? Let me know if there's already a way to do this that I haven't found!