Adding a menu item type

Menu item types allow execution of Joomla componentand can be used to control which views, layouts and tasks are trigered by component's controller. To add a new menu item type to the menu manager simply create default.xml with the following content in the /components/com_MYCOMPONENT/views/MYVIEW/tmpl/ folder:

 

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="Menu Title">
        <message>Menu description</message>
    </layout>
</metadata>

The above file will add a new menu type called Menu Title with the following link:

index.php?option=com_MYCOMPONENT&view=MYVIEW

If you create an XML file with a different name ie otherview.xml, Joomla will add layout parameter to the Link:

index.php?option=com_MYCOMPONENT&view=MYVIEW&layout=otherview

You can also add a task parameter to the link by adding the following code to your XML menu file:

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="Menu Title">
        <message>Menu description</message>
    </layout>
    <state>
        <fields name="request">
            <fieldset name="request">
                <field name="task" type="hidden" default="mytask"/>
            </fieldset>
        </fields>
    </state>
</metadata>

The above code will produce the following menu link:

index.php?option=com_MYCOMPONENT&view=MYVIEW&task=mytask

or

index.php?option=com_MYCOMPONENT&view=MYVIEW&layout=otherview&task=mytask

depending if you created a default.xml or some other.xml file.

 

 

Comments   

Ruso_x
# Ruso_x 2013-02-06 04:07
Useful for me, thx!
stargazer1682
# stargazer1682 2014-06-06 12:59
We're using a component that has category content, but no menu integration (and no MYVIEW folder in the views directory) how do we adapt this to create category menu item types? It works, just no menu options in the menu manager (develop made them for the module manager instead...)
Thanks
dvlancer
# dvlancer 2014-06-06 22:44
MYVIEW is just a place holder. You'd need to use a name of the view folder in views directory.
stargazer1682
# stargazer1682 2014-06-06 23:22
I'm sorry, I still don't quite understand; when I open the /components/com _MYCOMPONENT/vi ews directory for the component in question, there are a lot of sub folders, each with a TMP folder; I don't know where to put this XML file, and a comparison other components that are integrated hasn't helped.
dvlancer
# dvlancer 2014-06-07 00:07
This is sound right. You'd normally have several sub-folders in the views folder.

you will need to put the XML file in to one of those folders (views/subfolder_name/tmp)

Which of those sub-folders you will need, depends on the view you want to make available via the menu
stargazer1682
# stargazer1682 2014-06-07 00:55
Okay, great; thank you. And then the XML files is just automatically detected by Joomla or there a setting or file that need to point to it?
dvlancer
# dvlancer 2014-06-07 01:03
This is correct. Joomla will automatically detected the file and you will see the new menu type when adding a new menu.

 

Would you like to contribute?



Free business joomla templates