Joomla component not appearing in the menu item types

ubi picture ubi · Dec 29, 2011 · Viewed 11.1k times · Source

I just followed the joomla tutorials on how to create the "perfect" MVC joomla component. However, my problem is that I don't know yet how to assign it to a menu. I thought that my component would then just show up when I select a "menu item type", but my component is not on this list. I've made some research on Google, but I cannot find the answer... Do I have to create a metadata.xml file or something similar ? Thanks in advance for your answers !!

Answer

alghimo picture alghimo · Dec 30, 2011

To create "views" for your component, you have to create some xml files. Inside the templates folder in the frontend part of your component (usually something like /components/com_yourcomponent/views/someview/tmpl), if you had a template named default.php and form.php, you can create a default.xml file and a form.xml file to make these menu items available from the administrator. You can take a look at other components to see the structure of these xml files, but what you should put inside is:

1) A name and a description for four view 2) The params the user will be able to change from the administrator (it works like module/plugin params) 3) You can also set "hidden" request variables for that menu item. It means that those vars will be added to the request in that particular menu item, but the user won't be able to change its value.

Here's a complete example for a component (Joomla 1.7):

    <?xml version="1.0" encoding="utf-8"?>
    <metadata>
        <layout title="COM_AGMTAGS_TAG_VIEW_DEFAULT_TITLE">
           <message>COM_AGMTAGS_TAG_VIEW_DEFAULT_DESC</message>
        </layout>
    <fields name="request" addfieldpath="/administrator/components/com_agmtags/models/fields">
        <fieldset name="request">
           <field name="tag_id" type="agmtag"
            label="COM_AGMTAGS_TAG_FIELD_NAME_LABEL"
            description="COM_AGMTAGS_TAG_FIELD_NAME_DESC"
           />
        </fieldset>
    </fields>
    <fields name="params">
        <fieldset name="basic" label="COM_AGMTAGS_TAG_OPTIONS">
           <field name="layout_type" type="hidden" default="blog" />
       <field name="show_tag_name" type="list"
            label="COM_AGMTAGS_SHOW_TAG_NAME"
            description="COM_AGMTAGS_SHOW_TAG_NAME_DESC"
           >
              <option value="">JGLOBAL_USE_GLOBAL</option>
              <option value="0">JHIDE</option>
              <option value="1">JSHOW</option>
           </field>
           <field name="show_tag_description" type="list"
            description="COM_AGMTAGS_SHOW_TAG_DESCRIPTION_DESC"
            label="COM_AGMTAGS_SHOW_TAG_DESCRIPTION_LABEL"
           >
              <option value="">JGLOBAL_USE_GLOBAL</option>
              <option value="0">JHIDE</option>
              <option value="1">JSHOW</option>
           </field>
           <field name="items_per_page" type="text" default="" />
           <field name="container_class" type="text" default="agmtags-list" />
        </fieldset>
    </fields>
    </metadata>

I hope it helped!