有没有办法在shopify的css中获取页面标识符。
我想在shopify特定的页面做样式工作,而不是所有的页面。
所以我想指定页面,无论是主页还是我建立的页面,博客页面或购物页面等。
发布于 2016-04-09 15:11:06
您可以使用类似以下内容:
将theme.liquid中的<body>替换为以下内容:
<body class="{{ template }} {{ page.handle }}{% if template == 'collection' %}{{ collection.handle }}{% endif %}{% if template == 'product' %}{{ product.title | handleize }}{% endif %}{% if template == 'blog' %}{{ blog.handle }}{% endif %}{% if template == 'article' %}{{ article.title | handleize }}{% endif %}">若要向页的body元素添加类,请执行以下操作。
为了将其分解,我正在做以下操作:
{{ template }}
这将返回模板的名称(例如,主页的索引、博客页面的博客、商店页面的集合等等)
{{ page.handle }}
返回每个唯一页面的句柄( about-us、contact-us...只有页面,而不是集合、博客、产品)
{% if template == 'collection' %}{{ collection.handle }}{% endif %}{% if template == 'product' %}{{ product.title | handleize }}{% endif %}
在这里,我检查页面是否为集合{% if template == 'collection' %},以及页面是否为产品{% if template == 'product' %},并使用handleize filter {{ product.title | handleize }}添加集合{{ collection.handle }}的句柄和产品页面的标题。我检查页面,因为产品没有以正常的方式返回一个句柄,我使用的是标题,如果我不检查集合,它也会将其添加到产品页面。
{% if template == 'blog' %}{{ blog.handle }}{% endif %}{% if template == 'article' %}{{ article.title | handleize }}{% endif %}
这一逻辑与集合/产品逻辑相同。
一旦设置了上面的内容,就可以针对每个页面的body类设置样式。
发布于 2016-08-22 23:55:48
您可以在Shopify上添加新的页面模板。然后,您可以根据需要进行定制。完成后,您可以通过shopify管理面板选择页面模板。
为页面创建备用模板。从您的“购物”管理中,单击“在线商店”,然后单击“主题
找到要编辑的主题,单击...按钮,然后单击编辑HTML/CSS。
在Template文件夹下,单击Add a new template链接。
为您的新模板选择合适的选项(页面或产品等),并为模板指定一个有意义的名称(例如,page.no-sidebar)。
像往常一样编辑并保存新模板。
创建备用模板后,它将出现在模板下拉列表中。因此,如果您为产品创建了替代模板,您将看到在每个产品页面底部的新模板部分中选择模板的选项。
发布于 2019-05-16 17:20:59
是的,你可以通过类来识别页面。在shopify中,我们有不同的模板用于所有页面,主页,产品页面,收藏页面,购物车页面,博客页面。如果您转到标记,您可以找到类名template-name something.Its,它很容易识别页面,并且您将能够对特定页面应用css
或者,您可以在模板标题部分应用liquid代码。您只需要在theme.liquid文件中添加下面这一行,其中是主体标记
<body class="boyd test {{ template.name }}"> 我希望这对你有用。
https://stackoverflow.com/questions/36512354
复制相似问题