Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Conditional div based on page url using liquid

Community Beginner ,
Apr 22, 2015 Apr 22, 2015

Hi there,

I'm trying to have a div (header graphic at the top of a blog overall layout) that only appears on certain pages based on the page url. The goal is to only show this div on the blog index but not on any of the post pages. This seems like something I could accomplish with Liquid but I'm new to it and haven't been able to get it working. Here's what I've tried so far:

In overall.html:

{module_url render="collection" collection="urlcollection" template=""}

{% if urlcollection.ID == '/blog' --%}

<div class="blogheader">

blog name in an h1 tag in here

</div>

{% endif --%}

The header simply never appears now. And, if I include

<pre>{{urlcollection | json}}</pre>

in overall.html to see what the output is, I see this:

{

  "moduleName": null,

  "moduleDescriptor": {

  "templatePath": null,

  "parameters": "",

  "apiEndpoint": null,

  "objectType": "0",

  "objectId": "0",

  "adminUrl": null

  }

}

What am I doing wrong? Why is the collection empty? Any advice is appreciated.

Thanks!

TOPICS
Newbie Corner
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2015 Apr 23, 2015

module_url is a parameter module and its job is for custom parameters, not what your trying to use it for.

Always read the docs
Developer reference

You would want this - Developer reference

And you do not need to do a whole collection on it.

You can not say == either because its only part of a url, not the full url that you will want to check on something..

{% if {module_pageaddress} contains '/blog' -%}


Also if you see --%}  in the docs - this is an error, I already told them to fix it. It should only be one -

-%}

It will get fixed soon!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 23, 2015 Apr 23, 2015

Hi Liam,

I've tried this but strangely it doesn't work still. I tried both of the following snippets:

{% if {module_pageaddress} contains '/blog' -%}

div here

{% endif -%}

{% if {module_pagename} == 'Acme Corp Blog' -%}

div here

{% endif -%}

to no avail. The div never displays still. I made sure I am using the exact page name by checking what {module_pagename} prints out when inserted alone on the page, without the conditional.

Any other advice?

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 23, 2015 Apr 23, 2015

Resolved with the following:

{% if {{pageTitle}} == 'The Blog Title' %}

div with header image

{% endif %}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2015 Apr 24, 2015
LATEST

You do not need to do brackets inside liquid brackets. Your double rendering.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines