How to Add Submenu in Joomla Component

You can a submenu using a helper file. The file is stored in helpers folder with the same name as the name of component name (without com_), or else submenus won't show in category view.

Step 1


abstract class HelloWorldHelper extends JHelperContent
public static function addSubmenu($submenu)
JHtmlSidebar::addEntry('Messages', 'index.php?option=com_helloworld', $submenu == 'helloworlds');

JHtmlSidebar::addEntry('Categories', 'index.php?option=com_categories&view=categories&extension=com_helloworld', $submenu == 'categories');

The addEntry Function of JHtmlSidebar Class expects three parameters:

  1. Name - string
  2. Link - string (default value is empty)
  3. Active - true or false (default value is false)

You can also use JHtml class loader method like this:

JHtml::_('sidebar.addEntry', 'Messages', 'index.php?option=com_helloworld', $submenu == 'helloworlds');

Step 2

To import the helper class, edit the main entry file of the component, which is admin/helloworld.php file.


// Require helper file
JLoader::register('HelloWorldHelper', JPATH_COMPONENT . '/helpers/helloworld.php');

Add the code before creating an instance of the controller.

Step 3

Edit the view file to set the sub menu.


// Set the submenu

Add the code before setting the toolbar.

Step 4

Update the layout file (default.php) to display the sidebar.


<form action .... >
<div id="j-sidebar-container" class="span2">
<?php echo JHtmlSidebar::render(); ?>
<div id="j-main-container" class="span10">
<div class="row-fluid">
<div class="span6">
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this) ); ?>
<table class="table table-striped table-hover">


<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
<?php echo JHtml::_('form.token'); ?>


Star ActiveStar ActiveStar ActiveStar ActiveStar Active