首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shopify Liquid: If语句

Shopify Liquid: If语句
EN

Stack Overflow用户
提问于 2014-06-28 23:21:21
回答 1查看 19.2K关注 0票数 6

我正在尝试根据用户查看特定网页的时间启用div类,例如: blog、index或../ page /webpage

代码如下:

代码语言:javascript
复制
{% unless template contains "index" and settings.slideshow_enabled %}
   <div class="container main content">
{% endunless %}

该“容器主要内容”在导航栏后面显示了一个图像。在其他页面上,图像从导航栏下方开始。这里有一个明显的例子:http://retina-theme.myshopify.com/

我想有相同的主页,链接上面的链接,在选定的页面或模板:

代码语言:javascript
复制
{% if template == "index" and template == "page" and settings.slideshow_enabled %}
   <div class="container main content">
{% endif %}

到目前为止,我没有尝试过任何有效的方法。有什么建议吗?

编辑:

到目前为止,我还不能回答我自己的问题,但这是通过对javascript进行调整来实现的:

代码语言:javascript
复制
{% unless template contains "page" or template contains "index" and settings.slideshow_enabled %} 
 <div class="container main content"> 
{% endunless %}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-29 07:11:52

if语句中的多个条件在liquid中不能很好地工作。See a similar question here

一种选择是使用嵌套的if语句:

代码语言:javascript
复制
{% if template == "index" or template == "page" %}
  {% if settings.slideshow_enabled %}
    <div class="container main content">...</div>
  {% endif %}
{% endif %}

或者类似这样的东西:

代码语言:javascript
复制
{% if template == "index" or template == "page" %}
  {% assign correct_template = true %}
{% endif %}
{% if correct_template and settings.slideshow_enabled %}
  <div class="container main content">...</div>
{% endif %}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24468229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档