themhz
themhz

Reputation: 8424

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...

Upvotes: 4

Views: 6246

Answers (2)

Mohd Abdul Mujib
Mohd Abdul Mujib

Reputation: 13948

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');

Upvotes: 2

Mohammed Nagoor
Mohammed Nagoor

Reputation: 884

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"); 

Upvotes: 11

Related Questions