Support Forum

  • Page:
  • 1

Hiding module on log in ...

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

I recently found this hack on the joomla.org forum for replacing a module after a user logs in. I think this could be quite handy ... http://forum.joomla.org/index.php/topic,114630.0.html



It basically means that you can have one module displaying in one position for guests and another module displaying to logged in users in the same position.



From the forum:


[This hack is done in J! 1.0.11]



I had a situation where i had a menu that I wanted to replace with the User menu once a user was logged in. In other words I wanted to hide that public menu when a user logged in.



This is such a simple hack that I don't see why this couldn't be part of the core. It involves adding a parameter to the module's xml file (in my case mod_mainmenu.xml in /modules/ but you can add this parameter to any module you want to hide.



Simply insert this in the position you want in the module.xml file:

[code:1]Code:



<param name="show_registered" type="radio" default="1" label="Show Menu When Logged In" description="Show the menu also when a registered user is logged in">

<option value="0">No</option>

<option value="1">Yes</option>

</param>[/code:1]





Then open up: /includes/frontend.php and go to line 155. You should see this code:

[code:1]Code:



foreach ($modules as $module) {

$params = new mosParameters( $module->params );

[/code:1]

Insert immediately after that the following code:

[code:1]Code:



// HACK: added code to check if module should be shown when a user is logged in

if (!$params->get('show_registered', 1) && $my->id) {

// simply continue the loop without outputting this module

continue;

}

// --- end HACK ---[/code:1]



This will work for modules that don't have that parameter defined as it will default to 'display' (or 1) the module when logged in as per normal functionality.



Now you can go into your module configuration and set the radio button to 'No' for the module you want to hide from logged in users.



Enjoy.
  • Anthony Olsen's Avatar
  • Anthony Olsen
  • LIfetime Developer - Big Bamboo
  • 23925 posts
  • 788 Thanks
  • Karma: 433
The administrator has disabled public write access.
hello,

do u have any suggestions for doing this in J1.5?

thank you!
  • rw1's Avatar
  • rw1
  • Free Extensions
  • 3 posts
  • Karma: 0
The administrator has disabled public write access.
answer is here:

forum.joomla.org/viewtopic.php?f=472&t=375030&p=1597668

woo hoo! :)
  • rw1's Avatar
  • rw1
  • Free Extensions
  • 3 posts
  • Karma: 0
The administrator has disabled public write access.
Hey Robin,

Thanks for posting that - Im sure itll come in handy.

Cheers Anthony
  • Anthony Olsen's Avatar
  • Anthony Olsen
  • LIfetime Developer - Big Bamboo
  • 23925 posts
  • 788 Thanks
  • Karma: 433
The administrator has disabled public write access.
you're welcome! i dig joomla bamboo, very nice designs and approach. do you have an extensions demo site? thanks, rw1 :)
  • rw1's Avatar
  • rw1
  • Free Extensions
  • 3 posts
  • Karma: 0
The administrator has disabled public write access.

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

Happy Campers