Page 1 of 1

Relative path to module sub-template?

Posted: Tue Sep 06, 2011 1:10 am
by yngwie
I am trying to write a module with an admin page. The admin page has three tabs. Instead of cramming all three tabs into one template I was trying to have the main template include each tab as a sub-template, using {include file='sub_template.tpl'}. This did not work. The file could not be found. I tried a whole bunch of relative paths but could not find one that works. Giving the absolute path to the file works but of course is not a portable solution.

What is the relative path to a module template file, or is there a better way to do what I am trying to do?

Re: Relative path to module sub-template?

Posted: Tue Sep 06, 2011 1:15 am
by calguy1000

Code: Select all

$this->ProcessTemplate('filename.tpl');
will look in the modules 'templates' directory.

Re: Relative path to module sub-template?

Posted: Tue Sep 06, 2011 10:53 am
by yngwie
I use $this->ProcessTemplate('filename.tpl') in action.defaultadmin.php to process the main template, but I want something to put inside the main template to include the sub-templates. The include-tag seems like a good candidate, only I don't understand how to get the path right.

Re: Relative path to module sub-template?

Posted: Tue Sep 06, 2011 2:36 pm
by yngwie
OK, I have been thinking. Perhaps the cleanest solution would be to implement each tab as a separate action? Now my main template would look something like this:

Code: Select all

{$tabs_start}
	{$tab_start_task1}
		{MyModule action='admin_task1'}
	{$tab_end}
	{$tab_start_task2}
		{MyModule action='admin_task2'}
	{$tab_end}
	{$tab_start_task3}
		{MyModule action='admin_task3'}
	{$tab_end}
{$tabs_end}
The action.defaultadmin.php would simply setup the $tab* variables and output the main template, while all the tab specific processing would be moved to action.admin_task1.php, action.admin_task2.php and action.admin_task3.php.

What do you think? Is this a good approach?

Re: Relative path to module sub-template?

Posted: Wed Sep 07, 2011 1:54 pm
by calguy1000
if you look at the action.defaultadmin.php of a couple of modules... News, Products, CGFeedback, etc. you will see that we do quite a bit more in php because there are things like permissions, preferences etc, that probably need to be checked to limit the ability of certain users, or to customize what is displayed for those users.

After that, we usually do something like:

Code: Select all

echo $this->StartTab('sometabalias');
include(dirname(__FILE__).'/function.admin_tab_sometabalias.php');
echo $this->EndTab();
in the function.admin_tab_sometabalias we do more security checks, and the functionality for that one tab, and at the end usually a

Code: Select all

$this->ProcessTemplate('filename.tpl');