liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Clarification on default filter syntax for Object/Hash creation

Open MelSFNL opened this issue 4 months ago • 2 comments

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.

MelSFNL avatar Aug 15 '25 12:08 MelSFNL

Hey @MelSFNL — interesting discovery! I didn't know this was possible… it shouldn't be. I can confirm that it's not unique to Silverfin though (tested in Shopify's flavor and it does work).

We recognize the need for an official way to do this, and have a plan for it. We should be able to get to it soon™ (before end of year).

benjaminsehl avatar Sep 10 '25 21:09 benjaminsehl

Hey @MelSFNL — interesting discovery! I didn't know this was possible… it shouldn't be. I can confirm that it's not unique to Silverfin though (tested in Shopify's flavor and it does work).

We recognize the need for an official way to do this, and have a plan for it. We should be able to get to it soon™ (before end of year).

@benjaminsehl thanks for your reply! I will be watching the issue and we are looking forward to further developments on this. Do you mind leaving the issue open?

MelSFNL avatar Sep 15 '25 07:09 MelSFNL