All things Shopify and commerce
Hi, this might even be the wrong approach, so if you have a better suggestion, let me know.
I'm building an app with theme blocks and I'm using product metafields with a namespace of the $app:my-namespace kind. This works well, since if I do (123456 is the app id, for those not in the know):
{{ product.metafields.app--123456--my-namespace.data.value.field }}
It shows whats in there correctly. But I have a lot of blocks and if I'm gonna have multiple apps (for development and such) I don't want to go to each of them and change it, I'd rather have it all in one place, so I created an "appid.liquid" snippet
{%- assign app_id = "123456" -%} {%- assign metafield_key = "app--" | append: app_id | append: "--my-namespace" -%} {{- metafield_key | strip -}}
Then in each block I have this (because I thought the whitespaces where the problem)
{%- capture metafield_key -%}{%- render 'appid' -%}{%- endcapture -%} {%- assign metafield_key = metafield_key | strip | strip_newlines -%} {{ product.metafields[metafield_key].data.value.field }}
metafield_key contains the correct values because I've printed it and copy pasted it to access the metadata and it works.
But the metafield information doesnt show, i've tried a
{{ product.metafields[metafield_key] }}
and it gives me a {}
I've also tried
{% assign metafield_value = product.metafields[metafield_key] | default: '' %} {{ metafield_value.data.value.field }}
And the other with the capture method and it just doesn't work.
Why doesn't it work? Is this even the best way to do this?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025