Page 1 of 1
[SOLVED] How to change template while RegisterRoute?
Posted: Fri Mar 23, 2012 9:22 pm
by kembl
Hello all!
I wonder if some one know how to assign some template for route.
I was try that:
Code: Select all
$this->RegisterRoute('@some/place/(?P<paramname>.*?)$@', array('action'=>'custom_action', 'showtemplate='=>'NotDefaultTemplate'));
but with out some success. Do not wont to change some core logics but it seems that no way to say which template use in route setup or later in action.custom_action.php, am i missing some?
Re: How to change template while RegisterRoute?
Posted: Fri Mar 23, 2012 9:49 pm
by calguy1000
'showtemplate' is reserved to disable the output of the cmsms page template, and just return the results of the {content} block.
Assuming your action understood the 'mytemplate' parameter (and you had set it's type with SetParameterType... you could use:
Code: Select all
$this->RegisterRoute('@some/place/(?P<paramname>.*?)$@', array('action'=>'custom_action', 'mytemplate='=>'NotDefaultTemplate'));
Re: How to change template while RegisterRoute?
Posted: Fri Mar 23, 2012 11:04 pm
by kembl
calguy1000 wrote:
Assuming your action understood the 'mytemplate' parameter (and you had set it's type with SetParameterType... you could use:
Code: Select all
$this->RegisterRoute('@some/place/(?P<paramname>.*?)$@', array('action'=>'custom_action', 'mytemplate='=>'NotDefaultTemplate'));
Thx for the fast answer!
This is main clue, I cant found (in documentation and forum) how to change curent page template "on the fly" from module code. So even if I got NotDefaultTemplate in "custom_action", I duno how to ask the CMS to use new template (by name or id) which listed in CMS templates.
In current time all routed sites use template from the page which marked as default in admin interface.
Re: How to change template while RegisterRoute?
Posted: Sat Mar 24, 2012 9:48 pm
by kembl
Hello all, today
After several cup of coffe, I almost found the way to set up differetn from default template for a page after RegisterRoute, without any changes in core CMS algorithm.
Lets see this beautiful workaround:
In the top of your action.custom_action.php ( this name only for example), you need to add:
Code: Select all
$content_obj = $gCms->variables['content_obj'];
$content_obj->LoadFromId(63);
where 63 is the PageId with desired template on it, this id you can see in admin panel where all site pages exists.
One little devil

still exists: if you need total empty page after RegisterRoute, for example, to out some ajax response, you cannot achive it with explaned aproach.
Cause, even with totaly empty template and empty style for this template, and no meta and etc., I still got
in a top of blank page... I wonder if some one know how to clean up this last two annoing strings to achieve
best controlled results
Re: How to change template while RegisterRoute?
Posted: Sat Mar 24, 2012 11:51 pm
by Jo Morg
Has to come from the template... The code itself (core) doesn't post content, just provides methods to post it, or present it, IIRC...
Same should happen with modules, unless you fetch contents from other sources other than DB. Still there must be explicit tags on a template, otherwise an empty template is just that: an empty template.
Also make sure you have cleared the cache before you test your code output.
PS: AFAIK a {content} tag must exist at all times on a template, otherwise you will get some errors...
Re: How to change template while RegisterRoute?
Posted: Sun Mar 25, 2012 12:27 am
by Jos
I guess you should read Calguy's post more carefully
Re: How to change template while RegisterRoute?
Posted: Sun Mar 25, 2012 6:26 pm
by kembl
Jos wrote:I guess you should read Calguy's post more carefully
His answer has no sense for me, cause even if I got NotDefaultTemplate variable with template name in my action, I still not know how to ask system use template with that name when out page {content} block
Thax Jo Morg, it was my fault, I really found those strings in one template. Any way, I found on this forum approach to disable template processing through this code
Code: Select all
$this->RegisterRoute('@some/place/(?P<paramname>.*?)$@', array('action'=>'custom_action', 'showtemplate' => 'false'));
the quotas around false did the thing

this is funny
Meanwhile, still cant to show routed pages with its own templates. Is this really useless thing to implement it some way without hack the core? ¯\(°_o)/¯
Re: How to change template while RegisterRoute?
Posted: Mon Mar 26, 2012 8:19 pm
by xlilien
Hi, I am experiencing the same problem. When I open the link registered in the module's registerRoute method, the new page uses template which is set for homepage. I cannot understand this behaviour, I would like to set another layout template for the page. But obviously I am missing something...thanks in advance for any clues guys!
Re: How to change template while RegisterRoute?
Posted: Mon Mar 26, 2012 9:37 pm
by Jo Morg
Just by searching a bit:
one explanation....
If you take some more time to search deeper you will probably find more answers to your question. Also there is an API: you can consult it's DOC's
here. Click on
Class CMSModule methods...
HTH!

Re: How to change template while RegisterRoute?
Posted: Mon Mar 26, 2012 10:43 pm
by xlilien
Since now I am using process template method to display module content (if it were that one you were trying to hint me). My aim is to be able to display another layout template. Were you suggesting to use this method to use the layout template?
Re: How to change template while RegisterRoute?
Posted: Mon Mar 26, 2012 10:54 pm
by kembl
Oh my God, Jo Morg, I was tried this, and you are the best!!! This is exactly what i need
I use CMS not first day, but this task was not solved by me, because I did not clear understood the docs! In my mind returnid have slight other meaning
Jo Morg, since this forum has no "Thanks mod", I cant fix your win official, but you stay in my hart

and my mood goes better.
Any way, I'll mark this topic as:
......*☆.¸.☆*'
.....*☆.@@ ☆*'
...*☆.@@@@☆*'
....@
SOLVED@
...☆*@@@@`*☆.¸¸
.......\\\||///.
........\\||//.
.........ƸӜƷ.
..........\|/..♥
...........V....
Re: How to change template while RegisterRoute?
Posted: Mon Mar 26, 2012 10:57 pm
by Jo Morg
@kembl: thanks. Glad I could help.
@xlilien: Maybe (not sure if there are other ways) a different page with a different template attached to it and set this page ID as a returnID on the module (may be set on the module preferences, or as a tag parameter). Just a suggestion though.
The way most modules use to change templates is to generate their own templates, which can be administered from their own DB entries on the backend. There may be different approaches though, if I understand what you need correctly.