How can I use product tags within custom metafields in a tag?

Hi all!

I’m trying to get something like the following to work:

{% for t in product.tags %}
  {% if t contains 'sizechart' %}                     	
    {{ shop.metafields.custom_fields["{{ t }}"] }}
  {% endif %}
{% endfor %}

I am using a custom metafields app and the tag syntax is this: {{ shop.metafields.custom_fields[“FIELD-HANDLE”] }}

So I’m trying to make it possible to create tags within a product (say it’s sizechart_dress) that match the FIELD-HANDLE that goes into the custom metafields tag. That way it can automatically pull that tag and just automatically place it inside the metafields tag and pull the correct information.

I read that I could assign a variable such as:

{% assign sizeChartStyle = t %}

and then call that variable within a tag by using instead of {{ }} but that also did not work - and maybe that is because the metafields tag already has as part of its syntax?

There must still be a way to pull that product tag into the metafields tag!

Thank you for any help!

You may want to replace this part:

{{ shop.metafields.custom_fields["{{ t }}"] }}

with the following code:

{{ shop.metafields.custom_fields[t].value }}

Also, a single-character variables might be ambiguous as sometimes it’s hard to keep them unique, so you may want to use another template.

Here’s the code I’ve used on my store:

{% for product_tag in product.tags %}
  {% if product_tag contains 'sizechart' %}                     	
   {% assign metafield_value = shop.metafields.custom_fields[product_tag].value %}
   {% if metafield_value != blank%}
    {{ metafield_value }}

   {% endif %}
  {% endif %}
{% endfor %}