How can I hide a DIV on some pages?

Everything to do with Joomla! 2.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

How can I hide a DIV on some pages?

Post by vincebodie » Fri May 01, 2015 11:35 pm

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?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37458
Joined: Sat Apr 05, 2008 9:58 pm

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

Post by Webdongle » Fri May 01, 2015 11:48 pm

  • 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
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein

vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

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

Post by vincebodie » Fri May 01, 2015 11:56 pm

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?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37458
Joined: Sat Apr 05, 2008 9:58 pm

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

Post by Webdongle » Sat May 02, 2015 12:23 am

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.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein

vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

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

Post by vincebodie » Sat May 02, 2015 2:39 am

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.

vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

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

Post by vincebodie » Sat May 02, 2015 3:18 am

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?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 26129
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

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

Post by Per Yngve Berg » Sat May 02, 2015 8:50 am

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;?>">

vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

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

Post by vincebodie » Sat May 02, 2015 8:39 pm

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.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 26129
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

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

Post by Per Yngve Berg » Sat May 02, 2015 9:35 pm

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

vincebodie
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Thu Sep 02, 2010 3:57 am

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

Post by vincebodie » Wed May 06, 2015 2:58 pm

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


Locked

Return to “Templates for Joomla! 2.5”