The Joomla! ® Community Magazine

Display Different Menu Items for Registered and Non-Registered Users Using MetaMod

Written by | Saturday, 01 October 2011 00:00 | Published in 2011 October
Level of Difficulty:Beginner This tutorial is aimed at Joomla users who have grasped the basics and are just starting to require customization that needs something more than the standard Joomla toolbox.

It is a common requirement to want to display different menu options to registered and unregistered visitors.

Take for example the following menu structure as it would be displayed for public users, it contains a horizontal menu bar which includes the menu item 'Registration & Login':

Public Main Menu

When a visitor logs-in the menu is adjusted to include two extra menu options 'Payment' and 'Logout' that are only applicable to registered visitors.

Main Menu Registered Users

The displaying of menu items to registered visitors is achieved by simply setting the 'Payment' and 'Logout' menu option's Access Level to 'Registered' so that Public users do not see menus that are not applicable to them.

Access Level

However, for registered users, once they have logged in, the 'Registration & Login' menu option is no longer required and it would therefore be better if the 'Register & Login' menu option was not displayed.

It would be simple if Joomla, in addition to the Access Levels 'Registered' and 'Public', had a 'Public Only' option but it does not.

Those using Joomla 1.6 and higher are able to configure the ACL to hide the 'Registration & Login' menu option, but that option isn't available for those using Joomla 1.5.

There are various solutions and workarounds, some that rely on hacking the templates or CSS files, which may at first seem like a quick and simple solution, but may prove difficult to maintain. The less customizing of the templates and CSS the better. Too often a template can be customized, only for some the template or CSS files to be updated some months later and the customization forgotten about and suddenly a website that was working is no longer working and no one knows why.

A popular method to resolving this problem is by using the MetaMod extension, which is an easier solution to maintain and can also be used for more sophisticated configurations such as allowing the menus to be configured to a particular language, the time of day and location.

This article only demonstrates using MetaMod to display different menus to visitors who are in 'public' and 'Registered' mode.

For the example a horizontal menu is being used, but the instructions should be easily adapted to using any type of menu in any position.

The following assumptions are being made:

  • the reader has a basic understanding of Joomla and knows how to download and install extensions.
  • the website has been developed sufficiently to have a single menu that needs to be customized for the two login states.

Although in this case we are concentrating on catering to two different login states, it would be a good grounding for other types of customizations.

MetaMod method

Preparation

If the MetaMod module is not currently installed, then locate, navigate and download the MetaMod extension.

MetaMod Download

Use the Joomla install to include MetaMod, and then enable the MetaMod module.

It would be advisable to make a backup prior to starting Step 1.

Step 1

Assuming that the website has been developed initially using a single menu, select the Menu Manager option, and copy the existing full menu.

In this example we are using the Top Menu.

Select the Top Menu and click on the Copy button and confirm the copy.

Menu Manager

We are going to make two copies of the Top Menu.

Make one copy and give it a name that reflects the customization you require, in this case we will call it Public-Access-Top-Menu because we want this menu to reflect the non-logged in visitor's menu options.

Public Access Top Menu

We are now going to repeat the process and make a second copy and give it a suitable name; in this case we will call it 'Registered-Users-Top-Menu'.

Registered Users Top Menu

Step 2

We now want to customize each of the copied menus, for example the 'Public-Access-Top-Menu' we will remove the 'Payment' and 'Logout' menu options.

Customize Public Access Menu

We will then customize the second menu, for this example the 'Registered-User-Top-Menu', and remove the 'Registration & Login' menu item and leave the 'Payment' and 'Logout' menu options.

The access level can be left as Registered or made Public, when we have finished it won't matter because we won't be controlling the menu option using the Access Level.

Modify the Registered Users Menu

Step 3

We now go to the Module Manager.

Module Manager

At this point we have three menu modules all competing for the same space so the first thing we will do is turn off the display for the original menu (Top Menu) that we no longer need, in this case by editing the Top Menu.

Top Menu

We can either change the Menu Assignment to 'None' so that the menu is no longer displayed, or alternatively we could just disable the whole menu as we won't be using it.

Menu Assignment

Although we want to display the other two menus, we don't want to display them at the same time, but only display them when we need to, so we will edit the first copied menu module, i.e. in this case 'Public-Access-Top-Menu'.

Public Access Top Menu

And set the Show Title to 'No'

Set Enabled to 'Yes'

Set the position to the same as the 'Top Menu' that was copied, in this case 'user3'

Set the access level to 'Public'

Set the Menu Assignment to 'None'

Public Access Top Menu Configuration

(The menu assignment is set to 'none' because we don’t want the menu displayed until we have checked if the user is unregistered. This check will be performed by the MetaMod module that we have downloaded, which will control if the menu is displayed or not).

We do the same for the second menu we copied, i.e. Registered-Users-Top-Menu.

Registered Users Top Menu

Configure the settings the same as 'Public-Access-Top-Menu'.

Registered Users Top Menu Configuration

Step 4

We now have turned off the display for all the menu configurations. At this stage, if we were to preview the website, no top menu would be displayed.

We now need to edit the MetaMod module so we can control which menu gets displayed, and when.

Edit the MetaMod module and give the MetaMod module a suitable title.

In this case we have given it the title 'MetaModPublicRegistered'.

Set the Show Title to 'No' and the menu assignment to 'All' and the position to the same as the menus – in this case 'user3'.

MetaMod Configuration 1

On the right of the MetaMod configuration, display set the 'Style for included modules' to 'Naked' – if you don’t do this the top menu will probably be displayed lower than it should be.

Style for Included Modules Setting

In the PHP section, enter the PHP code to display the correct menus.

The ID's of the Public-Access-Top-Menu and Registered-Users-Top-Menu will be shown above the PHP code box. If they are not then it is probably because they have not been enabled.

For this example, if the user is not registered we want to display the menu ID 53 (PublicAccessTopMenu), but if they are registered we want to display the menu 54 (RegisteredUsersTopMenu).

We enter the PHP code to do this, and there are a number of different statements that will work, but we have used the 'if else if' statement.

MetaMod Configuration PHP

Save the MetaMod settings.

Step 5

We have now finished configuring everything we need, so now all we need to do is check that the configuration works.

For users who are not registered, if the configuration is correct, they will see the menu that includes the 'Registration & Login' menu and excludes the 'Payment' and 'Logout' menu options.

Menu Displayed to Public Users

Once registered, the MetaMod should switch the menu modules and show the menu configuration that includes the 'Payment' and 'Logout' menu options, but excludes the 'Registration and Login' menu option.

Menu Displayed for Registered Users

Using the MetaMod solution does require that at least two menus be maintained, but providing a single menu is used initially, it is fairly easy to maintain a master menu that is then not active, but can be used to easily copy, and then the copied menus, customized.

Read 25762 times
Tagged under Designers
Martin Day

Martin Day

Old timer developer.

Leave a comment

Make sure you enter the (*) required information where indicated.

[b] [i] [u] [s] [url] [quote] [code] [img]   

Comments (11)

  • avatar
    • 2
    • 0
    Brian Teeman

    Wow - great tutorial - but what a complex scenario and ONLY relevant for Joomla 1.5.

    With Joomla 1.7 the provided ACL makes this incredibly simple to do and actually will take you less time than it did to read this article.

    here

  • avatar
    • 3
    • 0
    Martin Day

    Brian I totally agree that achieving the same effect using 1.6 and above is so much simpler, but the same MetaMod principles can be used for more than just testing for 'registered' and 'unregistered' states, such as language, time of day, subscription levels etc etc. and so using the same principles the MetaMod extension can still provide improved functionality to 1.6 and above users.

  • avatar
    • 0
    • 0
    Paul Orwig

    Martin, thank you for contributing this thorough and helpful tutorial.

    With millions of installed Joomla! 1.5 websites, I am sure there will be many sitebuilders and end users who will benefit from reading this information.

  • avatar
    • 2
    • 0
    Stephen Brandon

    Martin, thanks for such a great and well-written tutorial.

    As Brian said, this particular use-case (logged in/out users) can be covered by existing Joomla 1.7 functionality, but as you replied, the general methodology of using MetaMod works well for many other uses.

    I like to think of modules as building blocks, and MetaMod helps me to combine those building blocks onto a page in different combinations, based on any criteria.

    The only concern that I have about the tutorial is the duplication of menus. The problem with doing that is that it creates duplicate Itemids for essentially the same page(s), and this can also mess with SEF URLs. And don't get me started on VirtueMart Itemid Hell�!

    What I've been recommending lately for varying menu display is to tackle the menu items on the "display" side rather than the "entire menu" side. If you're using the standard mod_mainmenu module (J1.5) or mod_menu (J1.7), then I've created a free GPL drop-in alternative called ElastiMenu (metamodpro.com/software/elastimenu). This extends Joomla's menu module by giving the ability to nominate some of the menu items to NOT display, on a per-module basis. You can also tell it to display the menu items from more than one Joomla menu, one after the other but as part of the same module.

    So with ElastiMenu you can set up 1 module that shows some items, and another module that shows different items, based on the same underlying menu. That way you don't have to duplicate the menu, and you still use MetaMod to switch between the 2 versions based on whatever criteria you like. e.g. people from different countries see different menu items (GeoIP-based), or by time of day, browser type, domain, cookies, or sub-pages within components, like VM checkout pages.

    Anyway, thanks again for the great tutorial. I'm going to point people here in future!

    Stephen Brandon
    MetaMod developer

  • avatar
    • 1
    • 0
    Michael

    This can be done with the standard ACL in 1.7 - no need for metamod.

    This is described in detail on the ACL tutorial for 1.7 here

  • avatar
    • 0
    • 0
    Wazzu

    Thanks! You all can take a look at the documentation so you can make an idea on how to use it and the possibilities it brings
    http://www.metamodpro.com/metamod/configuration

  • avatar
    • 0
    • 0
    coilevi

    "Something you should be concerned about is duplicate content. That is, if you have any identical menu items in both menus, then unless you take steps to prevent it, you will end up with two different URLs pointing to the same page. Search engines like Google do not take kindly to this, and may rank the two almost-identical pages much lower than they would rank if there were only one page.

    The way to address this is to set up the first menu normally, then as you are setting up the second one, create menu items in it as “aliases” to the menu items in the first menu. In this way they should end up with the same URL no matter if you clicked on the first menu, or clicked on the corresponding item in the second menu."

    http://www.metamodpro.com/metamod/recipes/40-general/87-different-joomla-module- logged-in-logged-out

  • avatar
    • 0
    • 0
    Martin Day

    Although if this technique was adapted to other states duplicate content could be an issue as far as search engines go, in this particular case it is not as the search engines will not register and logon so will never see the registered/login pages.

  • avatar
    • 0
    • 0
    Alex Walker

    I use Metamod for switching a take-away menu on and off at different times on different days of the week, e.g Friday and Saturday openings are longer than during the week. Not sure the in-built ACL would be able to cover this ?

  • avatar
    • 0
    • 0
    Jonathan

    In only 5000 steps.

  • avatar
    • 0
    • 0
    Sivabalan

    I am using Joomla 2.5 In my site i have different type of users foe example HR,Manager,Leader and Members. For HR i have to list out all the menus like employee,project,leave,finance. For manager i have to list out employee,project,leave. For other members i have to list out only employee & leave.

    Please tell me how can i do it. I am beginner of Joomla.so please explain in detail please