Liquid seems to be very restrictive and I am not really able to figure out how to get the liquid equivalent of the below JS code:
const allIngredients = {
vitamin_c: {
title: "Vitamin C",
description: "Some text here",
},
vitamin_k: {
title: "Vitamin K",
description: "Some text here",
}
}
const productIngredients = ["vitamin_k"]
productIngredients.map(ingredient => {
console.log(allIngredients[ingredient])
});
Update:
I have multiple products and each product comprises of multiple ingredients. These ingredients are stored in product.Ingredients
.
Structure:
{
"vitamin_c" => {
"ingredient_title" => "Vitamin C",
"ingredient_description" => "Some text here"
},
"vitamin_k" => {
"ingredient_title" => "Vitamin K",
"ingredient_description" => "Some text here"
},
...
}
In the product metafield, I am adding the keys of the above json i.e. vitamin_c
and vitamin_k
.
Now what I want to do is to map the metafield values with the product.Ingredients
json and print the ingredient_title and the ingredient_description on my page.
Thanks for the help!