loadTemplate in another view

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
crazycoders
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Wed Jan 13, 2010 4:31 pm

loadTemplate in another view

Post by crazycoders » Thu Jul 08, 2010 3:44 pm

I have a component i'm building that layouts information in different ways depending on the user's selection in the component settings:

Code: Select all

		<param type="list" name="events_layout" label="Events layout">
			<option value="1">Calendar grid</option>
			<option value="2">Result list</option>
			<option value="3">Task list</option>			
		</param>
This layout option is not a "layout" per say for joomla. I did it this way so that users may default the way operations load when following a link or if users want a different display to be shown from a configurable form.

The problem is not really there because this works perfectly fine.

My question is, i've got the following views:

- events
- results
- teamcal
- teamresults

Which all displays pretty much the same information. If you look at the template folder for each of these views there are approximately 11 layout files ranging from default.php to default_calgrid_item_result.php. Now, if i had only one view or 2, changing information in each of the template files wouldn't be too long. But now i've got 4 and nothing says i won't have more later.

If i have a global change to do in one of the item files (2 types: results, events multiplied by 3 layouts: calendar, grid, tasklist multiplied by number of views) it gets long to change each file, remember to upload, change the repository.

So finaly, my question is pretty simple...

Can i create somekind of dummy view that contains the templates i want to load such as:

Code: Select all

$CalendarEngine = new JoomsportViewCalendarEngine();
echo $CalendarEngine->loadTemplate('calgrid_header_events');
Or anything similar that will allow me to put all changes to the calendar engine in one place. Another problem with this multiple repeated files is that people trying to extend the templates for their own skin will find it tedious to do it so many times.

Thanks

secteur
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 146
Joined: Tue Nov 08, 2005 9:32 am
Location: Malaysia

Re: loadTemplate in another view

Post by secteur » Wed Jul 14, 2010 11:08 am

Hi,

If I understand you correctly, I think the following should work:

Have your layouts in one of the views only (let's say results)
In your other views, before calling $this->loadTemplate( ), insert the path to your templates (the path from the results view)

Code: Select all

class JoomsportViewEvents extends JView {
 function display()
 {
  $this->addTemplatePath( JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_joomsport' . DS . 'views' . DS . 'results' . DS . 'tmpl' );
  $this->setLayout( 'calgrid' );
  echo $this->loadTemplate( 'header_events' );
 }
}
The above would load the calgrid_header_events layout which is in the results view.
You should not have the same layouts in the other views' "tmpl" folders though I think, otherwise there might be conflicts.

Hope this helps.

crazycoders
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Wed Jan 13, 2010 4:31 pm

Re: loadTemplate in another view

Post by crazycoders » Wed Jul 14, 2010 7:00 pm

Great, i'll test that out.

Peace man!

crazycoders
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Wed Jan 13, 2010 4:31 pm

Re: loadTemplate in another view

Post by crazycoders » Tue Aug 03, 2010 2:40 pm

Finaly had time to test it out. it Works Mighty fine. I will keep that in my favorites!


Locked

Return to “Joomla! 1.5 Coding”