[SOLVED] How to change template while RegisterRoute?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

[SOLVED] How to change template while RegisterRoute?

Post 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?
Last edited by kembl on Mon Mar 26, 2012 10:55 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to change template while RegisterRoute?

Post 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'));
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.
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

Re: How to change template while RegisterRoute?

Post 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.
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

Re: How to change template while RegisterRoute?

Post 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 >:D 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

Code: Select all

</__body>
<!-- start content -->
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???
Last edited by kembl on Sun Mar 25, 2012 5:31 pm, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to change template while RegisterRoute?

Post by Jo Morg »

Code: Select all

</__body>
<!-- start content -->
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...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: How to change template while RegisterRoute?

Post by Jos »

I guess you should read Calguy's post more carefully
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

Re: How to change template while RegisterRoute?

Post 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 :o :)

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)/¯
xlilien
Forum Members
Forum Members
Posts: 11
Joined: Thu Mar 08, 2012 10:51 pm

Re: How to change template while RegisterRoute?

Post 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!
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to change template while RegisterRoute?

Post 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! ;)
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
xlilien
Forum Members
Forum Members
Posts: 11
Joined: Thu Mar 08, 2012 10:51 pm

Re: How to change template while RegisterRoute?

Post 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?
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

Re: How to change template while RegisterRoute?

Post 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....
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to change template while RegisterRoute?

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Developers Discussion”