Page 2 of 2
To use PHP to modify the completely rendered template you would have to create a plug-in to handle the page rendered event and modify the page at the point just before it is served to the browser.
This is possible but once again seems like overkill for a change as small as rewriting a menu item depending on the state of the system.
The only other approach that allows PHP to be used would be to add the code to a custom module that was positioned so as to guarantee that it was processed after the menu module we need to modify. Now this is beginning to sound very messy and not a good way to work.
This all seems a lot simpler when we actually write out the code.
The first thing to do is get a user object:
and then test to see if the user is logged on or not:
The reason for the odd test is that a user not logged on has the status of guest but a logged on user can have a number of different states.
If the user is logged on then we create the script. If the user isn't logged on there is nothing to do because the menu item says "logon" by default:
Putting all of this together gives:
This can be inserted into the template anywhere that is legal. I placed it close to the menu it modifies complete with some comments to explain how it works but this is just to make maintenance easier.
With this addition to the template the Logon menu item
now changes to Logout when the user is logged in.
The Joomla MVC classes
You might know what the MVC pattern is all about, but to make the best of it in Joomla you need to understand the three MVC classes it provides.