Relative path to module sub-template?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
yngwie
New Member
New Member
Posts: 5
Joined: Fri Sep 02, 2011 1:25 pm

Relative path to module sub-template?

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Relative path to module sub-template?

Post by calguy1000 »

Code: Select all

$this->ProcessTemplate('filename.tpl');
will look in the modules 'templates' directory.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
yngwie
New Member
New Member
Posts: 5
Joined: Fri Sep 02, 2011 1:25 pm

Re: Relative path to module sub-template?

Post 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.
yngwie
New Member
New Member
Posts: 5
Joined: Fri Sep 02, 2011 1:25 pm

Re: Relative path to module sub-template?

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Relative path to module sub-template?

Post 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');
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”