125 votes
0 answers
shopify - dynamically calling liquid commands
Solution:
After replicating the same on my dev store, I found some weired that need to be removed then It will worked as desired.
{% assign main_dimensions = "width_cm, height_cm, depth_cm, length_cm" | split: ',' %}
{% assign main_dimensions_title = "Width (cm), Height (cm), Depth (cm), Length(cm)" | split: ',' %}
{% for i in main_dimensions %}
// when split it it adding the space infront of second element due to space before , in to string
{% assign key = i | remove: ' ' %}
{{ main_dimensions_title[forloop.index0]}} - {{ product.metafields.global.main_dimensions[key].value }} <br/>
{% endfor %}
so use remove to eliminate it or simply create the string like this bellow without spaces.
{% assign main_dimensions = "width_cm,height_cm,depth_cm,length_cm" | split: ',' %}
{% assign main_dimensions_title = "Width (cm), Height (cm), Depth (cm), Length(cm)" | split: ',' %}
{{ product.metafields.global | json }}<br/>
{% for i in main_dimensions %}
{{ main_dimensions_title[forloop.index0]}} - {{ product.metafields.global.main_dimensions[i].value }} <br/>
{% endfor %}
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.