GetSimple Support Forum

Full Version: [SOLVED] Remove component from one page not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Following the wiki, I need <?php if (return_page_slug()!='PAGE') get_component('COMPNAME'); ?> in my template.php to disable a component on a certain page.
It is not working for me.
I am trying to disable sidebar on a page.
I am adding the line right after <?php get_component('sidebar'); ?>

Anything I am missing?

Thank you.
Hi inteq,

If <?php get_component('sidebar'); ?> is in the template, the component will be present on every page. Delete the tag if you don't want it that way.

Regards
Add it instead not after.
Thank you for reply.
I want the Sidebar component to be present on all pages but on a few selected ones.

So far I discovered that:
if I comment out <?php get_component('sidebar'); ?>
and I add <?php if (return_page_slug()!='index') get_component('Sidebar'); ?>
I will get the Sidebar on all pages BUT index.

Now, if I want to remove the Sidebar from yet another page, my logic tells me that I should add another:
<?php if (return_page_slug()!='another_page') get_component('Sidebar'); ?>

But, if I do that, the Sidebar will be doubled on all pages and will appear once an the pages I want it removed.

One thing that does the trick is:
<?php if (return_page_slug()=='index') get_component('Sidebar'); ?>
<?php if (return_page_slug()=='another_page') get_component('Sidebar'); ?>
This way I will only get the Sidebar on those two pages but it is a bit hard to implement when one has a lot of pages Sad

Did I get it right?
(2014-10-22, 14:10:04)inteq Wrote: [ -> ]One thing that does the trick is:
<?php if (return_page_slug()=='index') get_component('Sidebar'); ?>
<?php if (return_page_slug()=='another_page') get_component('Sidebar'); ?>
This way I will only get the Sidebar on those two pages but it is a bit hard to implement when one has a lot of pages Sad

You can use the in_array() function to make it more slim.
First you create an array with your "blacklist-slugs", where no sidebar will be shown (or "whitelist-slugs", depends on what is less input):
PHP Code:
$noSidebar = array('page_without_sidebar1','page_without_sidebar2','page_without_sidebar3'); 
Then you check, the slug and output the sidebar:
PHP Code:
if( !in_array(return_page_slug(), $noSidebar) ) {
get_component('Sidebar');

Not tested, but it should work like this.
@moped Thank you!
It works like a charm.
Exactly what I wanted.
You can always make use of additional customfield plugin, and control the component from within page options just by checking what is the dropdown or checkbox state on the page.