Ardi94
October 12, 2021, 8:40pm
1
I’m trying to call specific metafields based on my product tags. Is it possible to call a metafield from a variable like below?
{% assign my_variable = 'bar' %}
call something like this
{{ shop.metafields.foo.my_variable.value }}
to get this
{{ shop.metafields.foo.bar.value }}
?
I have tried all these below with no luck
{{ shop.metafields.foo.my_variable.value }}
{{ shop.metafield.foo.[my_variable].value }}
{{ shop.metafield.foo.['my_variable'].value }}
Or even tried to put the entire metafield address into a variable but didn’t work.
my workaround currently is using pages and blogs to store the information but I’m trying to see if this is possible at all.
thank you
I think your issue is the dot "." before the dynamic access "[my_variable]"
Also metafields should be plural not singular, although that might have just been pseudocode.
The following liquid code should work:
{{ shop.metafields.foo[my_variable].value }}
Ardi94
October 15, 2021, 6:58pm
3
It worked, thank you very much. I had an extra “.” in there.
lmd3d
February 23, 2023, 11:12pm
4
Hi Danloomer,
I have a similar issue. I created a few metafields and made it available to orders. I am trying to call them for display on my order page through Printer Pro app.
I thought I would just need to do the following:
{{ order.metafields.custom.purchase_order_number }}
But nothing is displayed. Any suggestions?