Ad

How To Access Variable From The Variable

- 1 answer

I have added a Metafields Guru app in my shopify store. I have created some metafields there And I want them to access in my template. All these are easily accessible if I access them individually. But problem is that how could I access if the key field come from another variable. I want code snippet something like below one.

{{product.metafields.productmeta.{block.settings.patitle | downcase }}}

block.settings.patitle comes from section block in a loop. And same downcased title is used as an key in metafields.

Ad

Answer

You can capture that string as something like a key:

{% capture mykey %}{{ block.settings.patitle | downcase }}{% endcapture %}

Then you can try accessing your metafield with that variable as in:

{{ product.metafields.productmeta.mykey }}

If that does not work, then why not try the string interpelation:

{{ product.metafields.productmeta['{{block.settings.patitle | downcase }}'] }}

Enough experimenting should get you what you want.

Ad
source: stackoverflow.com
Ad