Shopify Liquid:如果声明 [英] Shopify Liquid: If Statement

查看:178
本文介绍了Shopify Liquid:如果声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户查看特定网页的时间来启用div类,例如:博客,索引或../page/webpage

I am trying to enable a div class based on when a user views certain web page eg: blog, index or ../page/webpage

代码如下:

{% unless template contains "index" and settings.slideshow_enabled %}
   <div class="container main content">
{% endunless %}

容器主要内容"在导航栏后面显示图像.在其他页面上,图像从导航栏下方开始.此处是一个清晰的示例: http://retina-theme.myshopify.com/

That "container main content" shows an image behind the nav bar. On other pages, the image starts from below the nav bar. A clear example here: http://retina-theme.myshopify.com/

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

I want to have that same homepage, link the link above, on selected pages or template:

{% if template == "index" and template == "page" and settings.slideshow_enabled %}
   <div class="container main content">
{% endif %}

到目前为止,我没有尝试过.有提示吗?

So far nothing I have tried worked. Any tips?

我还无法回答自己的问题,但这对javascript进行了调整:

I can't answer my own question as yet but this worked with a tweak to the javascript:

{% unless template contains "page" or template contains "index" and settings.slideshow_enabled %} 
 <div class="container main content"> 
{% endunless %}

推荐答案

if语句中的多个条件在液体中不能很好地工作. 在此处看到类似的问题.

Multiple conditions in if statements don't work so well in liquid. See a similar question here.

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

One option is to use nested if statements:

{% if template == "index" or template == "page" %}
  {% if settings.slideshow_enabled %}
    <div class="container main content">...</div>
  {% endif %}
{% endif %}

或者类似这样的东西:

{% 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 %}

这篇关于Shopify Liquid:如果声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆