在产品页面上使用带括号 [] 访问器的设置对象
Using settings object with brackets [] accessor on product page
产品页面上的 {{ settings[a_prop] }}
似乎发生了一些神奇的事情。似乎 {{ settings[a_prop] }}
相当于我 settings.html
中的 属性 a_prop_productname
(而不是 a_prop
,这对我来说更有意义)。这一切都发生在我的主题 product.liquid
中。
谁能解释一下 productname
是从哪里拉出来的?此外,通常 liquid 使用点符号表示 settings
... 为什么括号在这里起作用?我在互联网上的任何地方都找不到任何示例。
https://docs.shopify.com/themes/liquid-documentation/basics/handle#handles-created
Shopify 将根据您提供的 product/page/whatever 标题自动创建句柄。
https://docs.shopify.com/themes/liquid-documentation/basics/handle#attributes-handle
您可以同时执行 {{ obj[attr] }}
或 {{ obj.attr }}
来访问 object 属性。
{{ obj[attr] }}
表示 "access the property on obj with the value of the variable attr",{{ obj.attr }}
表示 "access the property attr on obj"。
产品页面上的 {{ settings[a_prop] }}
似乎发生了一些神奇的事情。似乎 {{ settings[a_prop] }}
相当于我 settings.html
中的 属性 a_prop_productname
(而不是 a_prop
,这对我来说更有意义)。这一切都发生在我的主题 product.liquid
中。
谁能解释一下 productname
是从哪里拉出来的?此外,通常 liquid 使用点符号表示 settings
... 为什么括号在这里起作用?我在互联网上的任何地方都找不到任何示例。
https://docs.shopify.com/themes/liquid-documentation/basics/handle#handles-created
Shopify 将根据您提供的 product/page/whatever 标题自动创建句柄。
https://docs.shopify.com/themes/liquid-documentation/basics/handle#attributes-handle
您可以同时执行 {{ obj[attr] }}
或 {{ obj.attr }}
来访问 object 属性。
{{ obj[attr] }}
表示 "access the property on obj with the value of the variable attr",{{ obj.attr }}
表示 "access the property attr on obj"。