Die von Ihnen angeforderte Seite ist derzeit nicht in Ihrer Sprache verfügbar. Sie können eine beliebige Webseite umgehend mit der in Google Chrome integrierten Übersetzungsleiste in eine Sprache Ihrer Wahl übersetzen.
Oct 15, 2020

How to exclude sidebar based on url

How can I hide a section in my blogger template (contempo) on page load based a string present in the url?  

In particular I'd like to hide the aside / sidebar-container based on a url parameter that is present, for example myblog.com/p/mypage.html?sidebar=hide

Note I'm not looking to use display:none as that still loads all of the aside content from the template adding to page load time and extra bulk.  I'm looking to exclude it from the template section code based on a string contains (or similar) condition.

For example, I'd love to be able to use something like <b: if cond= to exclude a section from the template, BUT in my case I need something like <b: if cond CONTAINS mystring  (    the key difference being the use of CONTAINS instead of =    

I've been looking for an answer to this for months off and on with no replies on how to do it.

Thank you if you can help.
Locked
Informational notification.
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
All Replies (7)
Hi Ace,
 
it is a little tricky, but definitely possible to exclude blog elements conditionally.
 
Since this involves hacking your theme code, be sure to back up your current theme before you start.
Just to be clear: it is the conditional mechanism that I am referring to. You'll have to fit your code into that.
Oct 15, 2020
Thanks, I'm aware of the conditional codes you mention.

The problem is they only work on == and !== whereas I need something like CONTAINS string.

e.g. I want a section included if url is just /p/mypage.html and I want the section excluded if my url is /p/mypage.html?sidebar=hide  (in other words, exclude section if the url CONTAINS the string sidebar=hide)

Make sense?
Oct 15, 2020
I received help on stackoverflow with a workaround using ?view=hide-sidebar  
https://stackoverflow.com/questions/64375158/hide-section-of-blogger-template-on-page-load-based-on-a-string-present-in-the-u

<b:if cond='data:blog.view == "hide-sidebar"'> 
 <!-- don't show sidebar --> 
</b:if>

'view' must be named 'view'
'hide-sidebar' can be whatever you want

And you can use either == or != depending on your usecase

For example, adding these two bolded lines below in my Contempo template worked to hide the entire sidebar / aside if the page url is https://www.myblog.com/p/mypage.html?view=hide-sidebar

<b:if cond='data:blog.view != "hide-sidebar"'>
  <aside class='sidebar-container container sidebar-invisible' role='complementary'>
    ...lots of lines... 
  </aside>
</b:if>

This is a workaround, so I don't know if there could be unintended consequences using this.
false
5362390048264595635
true
Search Help Center
true
true
true
true
true
74
false
false
Search
Clear search
Close search
Main menu