Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I load a template of a view within another view in a component?

I am trying to add a view that I made (a table) to another view that I need to appear again. How can I do this? Actually I am trying to add a view within another view using theloadtemplate function.

This is what I type inside the view, but it does't seem to work, can anyone help? The message I get is the following

Layout default_reports not found

<div>
     <?php $jinput =  JFactory::getApplication()->input;
           $jinput->set('view', 'reports');
           echo $this->loadTemplate("reports");
           $jinput->set('view', 'master');?>
</div>

But the view is there...

like image 986
themhz Avatar asked Dec 16 '22 20:12

themhz


2 Answers

Using the loadTemplate function, we call only the layout inside the view.

We concatenate two or more layout using the loadtemplate inside the following view.

By default joomla, it call the layout by a prefix as default_. So we have to create a layout as reports means filename as default_reports.php but we need to call the layout as you have mentioned

echo $this->loadTemplate("reports"); 
like image 184
Mohammed Nagoor Avatar answered Dec 28 '22 09:12

Mohammed Nagoor


If you want to be able to load "layouts" from another "view" in the current view.html.php file, then you can do so as below.

$this->addTemplatePath(JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'anotherview' . DIRECTORY_SEPARATOR . 'tmpl');
$this->setLayout('layoutfromanotherview');
like image 44
Mohd Abdul Mujib Avatar answered Dec 28 '22 07:12

Mohd Abdul Mujib