GetSimple Support Forum
[SOLVED] Remove component from one page not working - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: [SOLVED] Remove component from one page not working (/showthread.php?tid=6876)



[SOLVED] Remove component from one page not working - inteq - 2014-10-22

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.


RE: Remove component from one page not working - Luigi - 2014-10-22

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


RE: Remove component from one page not working - shawn_a - 2014-10-22

Add it instead not after.


RE: Remove component from one page not working - inteq - 2014-10-22

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?


RE: Remove component from one page not working - moped - 2014-10-22

(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.


RE: Remove component from one page not working - inteq - 2014-10-23

@moped Thank you!
It works like a charm.
Exactly what I wanted.


RE: [SOLVED] Remove component from one page not working - yojoe - 2014-10-29

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.