6

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 %}
Sylar
  • 11,422
  • 25
  • 93
  • 166

1 Answers1

7

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 %}
Community
  • 1
  • 1
Steph Sharp
  • 11,462
  • 5
  • 44
  • 81
  • hi. This partially works for me: {% unless template contains "page" or template contains "index" and settings.slideshow_enabled %}
    {% endunless %}
    – Sylar Jun 29 '14 at 08:42
  • But this controls the static header: var $header = $(".index .header"); {% if settings.use_logo_home %} if ($(window).width() >= 768) { $('.logo img', $header).attr('src', $('.logo img').data('src-home')); } {% endif %} I need to add ".page" to it but I dont know javascript. – Sylar Jun 29 '14 at 08:43
  • @Sylar Just to check I understand your question, you want to show `
    ` on "index" and "page" templates if `settings.slideshow_enabled`? Or do you want to show that div for templates other than "index" and "page"? (In which case you could use `unless`)
    – Steph Sharp Jun 29 '14 at 10:33
  • If I have more than 3 statement in the `if` condition, should I always use at most 2 statements at once and nest them up? – Xiaodong Qi Dec 09 '16 at 06:03