Hello Community,
I am using product meta fields “mixed preference” with multiple selection, I am stuck on that I want for loop key so I want to add condition print my multiple choice.
Json Print of my custom fields is
[{"color_type":"Real Wood"},{"abrasion_resistance":"7000 Taber Cycles"}]
I want to add for loop with condition if key is color_type then show color type values and so on.
{% for additional in product.metafields.custom.additional_information.value %}
{% if additional.key == 'color_type' %}
Color Type
{{ additional.color_type }}
{% elsif additional.key == 'abrasion_resistance' %}
Abrasion Resistance
{{ additional.abrasion_resistance }}
{% endif %}
{% endfor %}
Like this, but I search shopify for loop not provide Key any alternative?
Thanks
First directly output the value of “additional” so you know it contains what you assume it does
{{ additional }} or {{ additional | json }} etc etc etc.
For some objects there’s also the .first and .last properties that applies, and bracket notation, e.g. additional[color_type]
When data is consistent you can avoid branching logic
{{ additional.key | replace:"_"," " }}
{{ additional.value }}
CSS to capitalize each word.
Otherwise to titlecase in liquid you have to do something like the following:
{{ additional.key | replace:“","remove” | camelize | replace:“remove”," " }}
Because the capitalize filter is only for the first word in a string and there is no titlecase filter.
Hi @iffikhan30 ,
I recommend exploring Easify Product Options, free plan available. This app allows you to seamlessly craft custom product options while incorporating a handy conditional logic feature. This functionality enables you to effortlessly determine and set up relationships between different options.
Hello, Thanks for your reply.
but my question is that, the shopify loop not provide key and value, If you want to show the customfield you just pass {{ additional.color_type }}, additional color_type and so on.
I want print key color_type,
{{ product.metafields.custom.additional_information.value | json }}
{% for additional in product.metafields.custom.additional_information.value %}
{{ additional.key | replace:"_"," " }}
{{ additional.value }}
{% endfor %}
When i add your code show empty