Skip to content

Clarification on default filter syntax for Object/Hash creation #1982

Description

@MelSFNL

Couldn't simply find something in the dev docs. Is this an intentional and supported feature?

It is currently possible to use the assign tag with a default filter to define key-value pairs for an object, as shown below:

{% comment %} Example from the documentation {% endcomment %}
{% assign client_address = client_address | default: street: "Innovation Drive 22", city: "Capital City" %}

{% assign client = client | default: name: "Future Solutions Ltd.", address: client_address %}

This effectively creates a nested hash, which can then be accessed using standard dot notation:

{{ client.name }}          // Outputs: Future Solutions Ltd.
{{ client.address.street }} // Outputs: Innovation Drive 22

This appears to be a very powerful and clean way to create hashes or objects directly within a Liquid template, which is a significant improvement over more complex workarounds like using capture with dynamic variable names or delimited strings, that we currently use a lot in Silverfin templates.

My Questions

  1. Is this default filter syntax for creating hashes an intentional and officially supported feature of Shopify's core Liquid library?
  2. If this is a standard feature, could you please point me to the official documentation for it? I was unable to find any mention of this specific usage in the Shopify Liquid documentation.
  3. Is this behavior dependent on a specific version of Liquid?
  4. If this is not a core feature, is it possible that this is a custom filter or extension implemented by the Silverfin platform?

Thank you for your time and for providing clarity on this matter.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions