Page 1 of 1

How can I hide a DIV on some pages?

Posted: Fri May 01, 2015 11:35 pm
by vincebodie
I know, I know... 'Menu Manager -> Edit Menu Item -> Page Display Options -> Page Class'

The DIV I am trying to hide has the ID '#s5_header_wrap' and I'm trying to hide it on the My Page menu item, such as here:
http://isurfedthere.com/home/surfers/my ... ferdiefoto

I have tried putting ' myspot' in Page Class (with a leading space and no quotes), but Firebug does not show any such classes on the page. I have emptied all caches.

By the way, I have this code in 'custom.css':

Code: Select all

div.myspot {
display:none;
}
Will that work? And am I on the right track?

Re: How can I hide a DIV on some pages?

Posted: Fri May 01, 2015 11:48 pm
by Webdongle
  • Create a copy of your default template
  • Edit the index.php of the copy to remove the div (or comment it out <!-- <div> </div>)
  • Assign the copy to the menu item

Re: How can I hide a DIV on some pages?

Posted: Fri May 01, 2015 11:56 pm
by vincebodie
Webdongle wrote:
  • Create a copy of your default template
  • Edit the index.php of the copy to remove the div (or comment it out <!-- <div> </div>)
  • Assign the copy to the menu item
Thanks for the reply, but I'd rather not have two copies of my template to deal with. Then site wide changes become double work.

Any other ideas?

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 12:23 am
by Webdongle
vincebodie wrote:...

Thanks for the reply, but I'd rather not have two copies of my template to deal with. Then site wide changes become double work.
...
How would site wide changes become double work ? All the other module positions will be exactly the same. Once you assign the copy to the menu item to the copy you do not need to touch the copy again. Unless you want to hide the div on another menu item ... in which case it is easier to assign the copy to it than it will be to rewrite the css again.
I have tried putting ' myspot' in Page Class (with a leading space and no quotes), but Firebug does not show any such classes on the page. I have emptied all caches.
If the class suffix is not being rendered then tthe Template probably is missing

Code: Select all

<div class="item-page<?php echo $this->pageclass_sfx; ?>
the

Code: Select all

<?php echo $this->pageclass_sfx; ?>
Renders the page class suffix ... if the variable is not there then the page class suffix won't be displayed.

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 2:39 am
by vincebodie
Webdongle wrote:
vincebodie wrote:...

Thanks for the reply, but I'd rather not have two copies of my template to deal with. Then site wide changes become double work.
...
How would site wide changes become double work ? All the other module positions will be exactly the same. Once you assign the copy to the menu item to the copy you do not need to touch the copy again. Unless you want to hide the div on another menu item ... in which case it is easier to assign the copy to it than it will be to rewrite the css again.
I have tried putting ' myspot' in Page Class (with a leading space and no quotes), but Firebug does not show any such classes on the page. I have emptied all caches.
If the class suffix is not being rendered then tthe Template probably is missing

Code: Select all

<div class="item-page<?php echo $this->pageclass_sfx; ?>
the

Code: Select all

<?php echo $this->pageclass_sfx; ?>
Renders the page class suffix ... if the variable is not there then the page class suffix won't be displayed.
With two templates I would need to change code twice if I want a site-wide change to CSS that is affecting an element on both templates, no?

You're absolutely correct about the missing PHP, gonna go take a whack at that right now.

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 3:18 am
by vincebodie
OK I have changed the code for that DIV on index.php from:

Code: Select all

<div id="s5_header_wrap">
to:

Code: Select all

<div id="s5_header_wrap" class="no_header<?php echo $this->pageclass_sfx;?>">
But the DIV is still not picking up the class suffix '_hidden'. Ideas?

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 8:50 am
by Per Yngve Berg
You need some more code.

Code: Select all

$app             = JFactory::getApplication();

// Getting params from template
$params = $app->getTemplate(true)->params;
$itemid   = $app->input->getCmd('Itemid', '');
$menu     = $app->getMenu();
$menuParams = $menu->getParams($itemid);
$pageclass_sfx  = $menuParams['pageclass_sfx'];
?>
<div id="s5_header_wrap" class="no_header<?php echo $pageclass_sfx;?>">

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 8:39 pm
by vincebodie
Per Yngve Berg wrote:You need some more code.

Code: Select all

$app             = JFactory::getApplication();

// Getting params from template
$params = $app->getTemplate(true)->params;
$itemid   = $app->input->getCmd('Itemid', '');
$menu     = $app->getMenu();
$menuParams = $menu->getParams($itemid);
$pageclass_sfx  = $menuParams['pageclass_sfx'];
?>
<div id="s5_header_wrap" class="no_header<?php echo $pageclass_sfx;?>">
Per,
Looking back through the threads I see that I forgot to mention that I had tried similar code blocks to your first one just before the opening <head> tag, based on info I had found in the Joomla docs:

1.

Code: Select all

<?php
  $app = JFactory::getApplication();
  $menu = $app->getMenu()->getActive();
  $pageclass = '';
  if (is_object($menu))
    $pageclass = $menu->params->get('pageclass_sfx');
?>
2.

Code: Select all

<?php
  $itemid = JRequest::getVar('Itemid');
  $menu = &JSite::getMenu();
  $active = $menu->getItem($itemid);
  $params = $menu->getParams( $active->id );
  $pageclass = $params->get( 'pageclass_sfx' );
?>
Your code didn't work out of the box (Fatal Error), but I tweaked it a bit:

Code: Select all

<?php
$app = JFactory::getApplication();
// Getting params from template
$params = $app->getTemplate(true)->params;
$itemid   = $app->input->getCmd('Itemid', '');
$menu     = $app->getMenu();
$menuParams = $menu->getParams($itemid);
$pageclass_sfx  = $menu->getParams('pageclass_sfx');
?>
I also tried several variations on the DIV code along with the above:

1. This had no effect on the DIV's class:

Code: Select all

<div id="s5_header_wrap" class="no_header<?php echo $this->params->get('pageclass_sfx')?>">
2. This at least shows signs of life along with your tweaked code; Firebug now shows the DIV as "class="no_header{}" (with empty squiggly brackets):

Code: Select all

<div id="s5_header_wrap" class="no_header<?php echo $pageclass_sfx;?>">
Next? This can't be that difficult, but then again I suppose I should learn me some PHP.

Re: How can I hide a DIV on some pages?

Posted: Sat May 02, 2015 9:35 pm
by Per Yngve Berg
Just noticed that you are working with J2.5. My 3.x code will not work.

https://api.joomla.org/cms-2.5/classes/ ... od_getMenu

Re: How can I hide a DIV on some pages?

Posted: Wed May 06, 2015 2:58 pm
by vincebodie
Per Yngve Berg wrote:Just noticed that you are working with J2.5. My 3.x code will not work.

https://api.joomla.org/cms-2.5/classes/ ... od_getMenu
Pardon me for my ignorance, but how does this fit in with the code you provided above?:

Code: Select all

getMenu(string $name = null, array $options = array()) : \JMenu