我们在shopify独立站开发过程中,有些模块只想让他在首页或者特定页面显示,怎么在shopify中判断呢。代码如下(“index”修改成其他可实现不同判断)
{%if template.name == "index"%}
需要显示在首页的代码,放到这里
{% endif %}
//下面的写法也行
{%- if request.page_type == 'index' -%}
需要显示在首页的代码,放到这里
{%- endif -%}
//下面的代码判断url里面包含“about-us”则显示特定的数据
{%if request.path contains 'about-us' %}需要显示在首页的代码,放到这里{% endif %}
liquid request能取到的数据类型如下
https://shopify.dev/docs/api/liquid/objects#request