Board index General discussions Hide sidebar section on particular pages?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Christine
Regular
 
Posts: 51
Joined: Thu Mar 26, 2009 12:50 am

Postby Christine » Mon Aug 07, 2017 3:10 am

I was wondering if there is a way to hide a sidebar section on specific pages. For example, I have a Blogroll page, and a blogroll sidebar widget (using html_nugget), and I'd like the sidebar blogroll to be hidden only when viewing the Blogroll page.

User avatar
yellowled
Regular
 
Posts: 6800
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Mon Aug 07, 2017 9:36 pm

Christine wrote:I was wondering if there is a way to hide a sidebar section on specific pages. For example, I have a Blogroll page, and a blogroll sidebar widget (using html_nugget), and I'd like the sidebar blogroll to be hidden only when viewing the Blogroll page.

Technically yes, but it's not going to be a “nice and easy” solution (as far as I can see). It will require hacking your theme's template files, it will only work if you use only the one html nugget, and it will likely break if you ever switch themes.

The problem with this is twofold

  • There is no good way in template files which static page you're currently on. There is a way to identify a static page (I assume your blogroll is a static page and not an entry?), but that might change if you edit the (title of the) static page.
  • There is no good way to identify a single sidebar plugin if said plugin can be installed multiple times (which the html nugget can be).
So if you only use the one html nugget, intend to only ever use the one html nugget and are not afraid of terms like “fork your current theme” and “edit template files”, I can try to outline a way to do this.

If you prefer an easy solution, I would suggest to just replace the sidebar blogroll with a link to the blogroll page. :)

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

Christine
Regular
 
Posts: 51
Joined: Thu Mar 26, 2009 12:50 am

Postby Christine » Tue Aug 08, 2017 4:21 am

I do have a few html nuggets, so I guess that's out!

yellowled wrote:
If you prefer an easy solution, I would suggest to just replace the sidebar blogroll with a link to the blogroll page. :)



I've decided this is best, as the Blogroll made the sidebar look too crowded.

I was also hoping to hide another html nugget on the start page - I guess this would at least avoid the issues with the static page, but there is still the problem of having multiple html nuggets. Would copying the html nugget plugin and giving it a new name work for this?

It's not that crucial but I'm just curious now.

User avatar
yellowled
Regular
 
Posts: 6800
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Tue Aug 08, 2017 9:01 pm

Christine wrote:Would copying the html nugget plugin and giving it a new name work for this?

Not sure if I understand what you mean by that, but if you're thinking of copying a plugin like copying a theme (with a changed name), I'm not sure if that would work. (But I never thought of trying that, either.)

Sorry we don't have a good solution for this, but this is an edge case. :(

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

Christine
Regular
 
Posts: 51
Joined: Thu Mar 26, 2009 12:50 am

Postby Christine » Wed Aug 09, 2017 3:26 am

yellowled wrote:Not sure if I understand what you mean by that, but if you're thinking of copying a plugin like copying a theme (with a changed name), I'm not sure if that would work. (But I never thought of trying that, either.)


I have done it before following advice on here. It works, the only issue is if there are any crucial updates to a plugin, you'd have to maybe copy and customise it again.
yellowled wrote:Sorry we don't have a good solution for this, but this is an edge case. :(


That's OK!

But to keep it simpler, if I wanted to hide a unique plugin, say the Linklist... is there any easy way to do that?

User avatar
yellowled
Regular
 
Posts: 6800
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Fri Aug 11, 2017 8:25 pm

Christine wrote:But to keep it simpler, if I wanted to hide a unique plugin, say the Linklist... is there any easy way to do that?

Not emitting a plugin is actually pretty simple if it's only one plugin. For example, I do this in the sidebar.tpl of 2k11 for quicksearch because 2k11 has a “hardcoded” search form in the header and no blog needs two search forms.

Code: Select all
{foreach from=$plugindata item=item}
{if $item.class != "serendipity_plugin_quicksearch"}
    <section class="sidebar_plugin clearfix {cycle values="odd,even"} {$item.class}">
        {if $item.title != ""}
        <h3>{$item.title}</h3>
        {/if}
        <div class="sidebar_content clearfix">{$item.content}</div>
    </section>
{/if}
{/foreach}

“Translated to English”, this means: we have a list of sidebar plugins ($plugindata); for each item in the list, test if it's class is not (!=) serendipity_plugin_quicksearch; if so, emit the plugin markup, if not, emit nothing. (Essentially: skip the quicksearch plugin.)

The hard part is to find a reliable identifier for the page on which you do not want to emit a given plugin. Even harder: this identifier (i.e. a variable that we can test in our template file) has to be available in sidebar.tpl, which is not the case for all variables in s9y.

So if you know which plugin you want to hide on which page, we can see if there's a way to hide it or not. I'm afraid there is no easy solution that will work for any plugin on any page of the blog.

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)

Christine
Regular
 
Posts: 51
Joined: Thu Mar 26, 2009 12:50 am

Postby Christine » Mon Aug 21, 2017 1:55 am

Thank you! I managed to hide the Linklist plugin on my Links page using:

Code: Select all
{if $item.class == "serendipity_plugin_linklist" &&  $staticpage_pagetitle == "Links"}
<!-- hide linklist -->
{else}
[my sidebar code here]
{/if}


ETA:
If I wanted to hide other plugins on different pages, would I just use {else if} and adjust the first line? Or is there another way?

User avatar
yellowled
Regular
 
Posts: 6800
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany

Postby yellowled » Mon Aug 21, 2017 8:19 pm

Christine wrote:If I wanted to hide other plugins on different pages, would I just use {else if} and adjust the first line?

Yes, but note that it's {elseif} in Smarty (one word). Smarty does not have a better control structures for that (like other languages do).

YL
amazon Wishlist - Serendipity-Podcast (German only, sorry)



Return to General discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron