Shopify Liquid-此JS代码在液体中等同于什么?

发布于 2025-01-26 14:00:06 字数 1069 浏览 1 评论 0原文

液体似乎非常限制,我真的无法弄清楚如何使液体等效于以下JS代码:

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])
});

更新:

我有多种产品,每种产品都包含多种成分。这些成分存储在product.Ingredients中。

结构:

{
  "vitamin_c" => { 
    "ingredient_title" => "Vitamin C",
    "ingredient_description" => "Some text here"
  },
  "vitamin_k" => { 
    "ingredient_title" => "Vitamin K",
    "ingredient_description" => "Some text here"
  },
  ...
}

在产品Metafield中,我添加了上述JSON IE Vitamin_CVitamin_k的键。

现在,我要做的是用product.Ingredients JSON映射Metafield值,然后在我的页面上打印IngreDient_Title和ingredient_description。

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文