Is there any way to call metafields image positions in variants? It works fine in liquid obviously, but I have one function which needs the data as well, but can only be loaded from javascript. I don’t have a problem getting variant.id or featured_image, however metafields I just don’t know what to do.
The liquid code (simplified) which fetches image positions is:
{%- for variant in product.variants -%}
<option data-image-positions="{{variant.metafields.variant.image_position}}">
</option>
{%- endfor -%}
Would appreciate some pointers.
2
Answers
JS always renders AFTER Liquid. So use Liquid to render values into your JS, and then you can freely use JS to do as you wish. Has always been a thing you can do.
You could do something like this, you can add below script in to markup
Your output will be
if any doubt please comment.