model-view-controllerjoomlasidebarsubmenujoomla3.4

Why does my MVC component for Joomla 3 have an empty sidebar?


I am changing my Joomla 2.5 component into a Joomla 3 component. However, it turned out to be one big obstacle course with hardly any documentation for it as far as I could find...

In Joomla 3 (using 3.5.1 at time of writing) the originally horizontal submenu goes vertical into the sidebar.

I called JHtmlSidebar::addEntry( "Item", "index.php?option=com_example", false ) to add a submenu item. Then called echo JHtmlSidebar::render() in the view's template file.

I do get a sidebar that can be opened and closed, but there are no items in it...

I downloaded the Hello World example component from https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_an_install-uninstall-update_script_file. It has a sidebar but it's a mess: in its Messages view there is a sidebar with items in it but not the collapsable one and in its Categories view the collapsable one appears empty and over the other sidebar:

Categories view with collapsable sidebar closed

Categories view with collapsable sidebar open

It also uses JSubMenuHelper (instead of JHtmlSidebar), which is deprecated...

I then tried to find out how it is done in Joomla's core com_installer, which has a nice collapsable sidebar with submenu items, but did not find more than what I already described above...

Anyone who can tell me how to get a proper sidebar? Thanks a lot already!!


Solution

  • And as it is so often: just after I posted my question I found the answer...

    In admin/controller.php I defined a method addSubmenu() in which JHtmlSidebar::addEntry() is called. I called addSubmenu() from the method display(), but I accidentally did that after calling parent::display(), so no entries where added yet when that method was executed.

    Now calling addSubmenu() before calling parent::display() and getting a very nice sidebar as result.