Shopify Liquid: If Statement

对着背影说爱祢 提交于 2019-12-02 05:06:50

问题


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

The code is like this:

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

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?

Edited:

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

回答1:


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

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

Or something like this:

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


来源:https://stackoverflow.com/questions/24468229/shopify-liquid-if-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!