16 years 11 months ago
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.