Liquid, JavaScript, themes, sales channels
Recently Shopify released the ability to create Metafield Definitions for a List of Values. The content of these metafields is an iterable and accessed via the value property.
This works for most of the new content types. However some of the content types return either null or throw an internal error.
I've put together an exhaustive table of all the metafield list types and whether they work property or are broken. The code below the table can be used to recreate the issue. (with appropriately created metafield definitions)
list.weight (bug: meta.value throws internal error) list.volume (bug: meta.value throws internal error) list.dimension (bug: meta.value throws internal error) list.page_reference (bug: meta.value is null) list.rating (bug: meta.value throws internal error) list.date (works) list.date_time (works) list.number_integer (works) list.number_decimal (works) list.product_reference (works) list.single_line_text_field (works) list.color (works) list.file_reference (works) list.url (works)
<!-- # WORKING EXAMPLES - where metafield.value returns a list of values list.single_line_text_field: json: {{ product.metafields.specs.textsingle_list.value | json }} el: {{ product.metafields.specs.textsingle_list.value[0] | json }} str: {{ product.metafields.specs.textsingle_list | prepend: "" }} # FAILING EXAMPLES - where metafield.value returns either null or throws an error list.page_reference: json: {{ product.metafields.specs.pageref_list.value | json }} el: {{ product.metafields.specs.pageref_list.value[0] | json }} str: {{ product.metafields.specs.pageref_list | prepend: "" }} list.rating_list: json: {{ product.metafields.specs.rating_list.value | json }} el: {{ product.metafields.specs.rating_list.value[0] | json }} str: {{ product.metafields.specs.rating_list | prepend: "" }} -->
<!-- # WORKING EXAMPLES - where metafield.value returns a list of values list.single_line_text_field: json: ["cat","dog"] el: "cat" str: ["cat","dog"] # FAILING EXAMPLES - where metafield.value returns either null or throws an error list.page_reference: json: "" el: null str: ["gid://shopify/OnlineStorePage/88645664920","gid://shopify/OnlineStorePage/91070595224"] list.rating_list: json: Liquid error: internal el: Liquid error: internal str: [{"scale_min":"0.0","scale_max":"5.0","value":"1.0"},{"scale_min":"0.0","scale_max":"5.0","value":"3.0"}] -->
Converting the entire metafield to a String via prepend "" was done to show that the metafield is in fact not empty. Unfortunately this is not useful when actually trying to iterate over the metafield contents.
User | RANK |
---|---|
21 | |
21 | |
8 | |
8 | |
7 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023