【发布时间】:2021-04-22 14:14:37
【问题描述】:
我在 Shopify 商店中遇到了以下挑战。
如果我想使用 ACF(高级自定义字段),我会在前端使用此代码:
{{product.metafields.warnhinweise.not-under-three-years}} 输出为:true
现在我想从翻译文件(locals/de.json)中输出一个变量,访问这个变量我必须使用:{{ 'products.productwarnings.not-under-three-years' | t }}
我想要完成的以及目前遇到的困难是:如何将自定义字段中的 ID 作为翻译变量中的变量名传递?
我尝试了以下方法:
<p>Example: {{ product.metafields.warnhinweise.not-under-three-years }}</p>
<ul>
{% for field in product.metafields.warnhinweise %}
<li>ID: {{ field | first }} - Value: {{ field | last }}</li>
<ul>
<li>normal way: {{ 'products.productwarnings.not-under-three-years' | t }}</li>
<li>nest the variable output: {{ 'products.productwarnings.{{field | first}}' | t }}</li>
</ul>
{% endfor %}
</ul>
但显然,这行不通。我怎么能完成插入 {{field |首先}} 到我的翻译变量中?
以上代码的输出如下:
Example: true
- ID: not-under-three-years - Value: true
- normal way: Achtung: Nicht für Kinder unter drei Jahren geeignet.
- nest the variable output: translation missing: de.products.productwarnings.field | first
我还从液体中收到语法错误:[dev-henry] (sections/product-template.liquid) Liquid syntax error (line 220): Unexpected character ' in "{{ 'products.productwarnings.field | first | t }}"
【问题讨论】: