Page 1 of 1

Modifying template to be used from within a module [CMSMS 1.9]

Posted: Mon Dec 06, 2010 1:32 pm
by jegmond
Hi all,

I'm writing modules (based off the Skeleton module) and I am trying to make it use different templates based on the flow of the module program logic. I'm running the 1.9 version of CMSMS.
Based on the thread in:
http://forum.cmsmadesimple.org/index.ph ... 721.0.html
it looks like I would have to use the returnid to modify the template. Is there a way from within a module to choose the template the final result should be put into? (preferably by using template names instead of obscure IDs).

The current module code is not specifying a template so it's using the same template as the default page, which in most circumstances is OK, but for some parts of the module I want a different template to be used (one optimized for printing information).

So the module for example registered the paths:
/printer/info  -> action.info.php
/printer/info/printable -> action.info.php
The last one should use a different template.

Is this possible?

Grtz,

Jeroen Egmond

Re: Modifying template to be used from within a module [CMSMS 1.9]

Posted: Mon Dec 06, 2010 5:48 pm
by Nullig
Have you tried a conditional branching, based on some variable you've set in your action.info.php?
Kinda like:

if($printing='1') {
  $this->ProcessTemplate('printing.tpl');
} else {
  $this->ProcessTemplate('noprinting.tpl');
}

Nullig

Re: Modifying template to be used from within a module [CMSMS 1.9]

Posted: Sun Dec 12, 2010 9:22 am
by jegmond
Yes, I tried that, but once the function ends it will continue with the rest of the CMSMS functions and it shows the results of the function as the {content} block in the template which the default page has (I could use an 'exit' but don't think that is a proper way to quit from a module?)
I want to be able to influence which final template is used to put the {content} block in.

The point is that my system is using different templates/layouts for different parts of the site (roughly it has three parts, a frontend, a backend and a printable-template).

I guess I could do it by making a page with the right template and use the {module param=""} replacement, but I was wondering if it was also possible to influcence the template to be used from with code of my module.

Looking at some of the properties of the gCMS object I found that there is a template defined, but it's only the number from the database which would not be practical (and even not sure if that property could be changed with the changes in the gCMS object changes which are going on :)

It would be nice to have some kind of (as final template to use)
$this->UseTemplate("name as defined in database");

Grtz,
Jeroen