0
votes

I'm trying to insert a metafield variable within an asset url as below:

{% assign review = product.metafields.review %}
{% assign key = 'rating' %}
<img src="{{ '[review.rating].png' | asset_url }}"/>

For some reason it isn't returning the actual variable, instead the text itself, is there a way to go about doing this?

1
Some more information about this would be helpful, try to include what you've tried and the language would also be very helpful. By the looks of it you are using the Django Template Language?Black Magic
It's in Shopify's Liquid Language - similar to that of JekyllsJMKelley

1 Answers

1
votes

If any reviews actually exist at the namespace product.metafields.review then you have to iterate through them. When you do that, for each iteration you'll get some key value pairs. With those you can print out the actual data of the metafield resources. What you are attempting there in your snippet seems a bit off. Try accessing the rating key in your iterator, and if it exists, the value would be available to you for your image snippet.