Load Layout From Another View

There are many times in Joomla when you need to include a layout from another view, this could be a side bar or a view that contains items that should be on each pages.

Step 1
Your layout in your view’s tmpl folder must be prefixed default_ so in our example I need to load a default_sidebar.php in another view.
If you are in the frontend, use the following codes to include the default_sidebar.php

$this->addTemplatePath( JPATH_COMPONENT.'/views/dashboard/tmpl' );
echo $this->loadTemplate('sidebar');

Change dashboard to the name of your actual view that contains the default_sidebar.php file.

Step 2
If you are in the Joomla backend, use the following codes, again change dashboard to the name of the actual view you are using.

$this->addTemplatePath( JPATH_COMPONENT_ADMINISTRATOR.'/views/dashboard/tmpl' );
echo $this->loadTemplate('sidebar');

That’s it. As you can see it is pretty simple to include a layout view. Leave a comment if you find this useful.

Please Post Your Comments & Reviews

Welcome to Western Studios

We provide professional website and mobile softwares including Joomla, Wordpress and more.