Skip to content

Question: Is there a way to track file nesting during render? #917

Description

@MihaxXx

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.liquidmain-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:

  1. Hooking into the TemplateParsed event
  2. Adding custom path tags with enter/exit flags at the beginning and end of each file
  3. 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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions