I want to be able to change the template associated with a page, based on certain parameters.
For example.
I have a global PHP variable that hold either "Desktop" or "Mobile". I want to display a page of content using the template "HomeDesktop" (by default) and "HomeMobile" if the variable is "Mobile".
I assume this is easy, but I don't know what I should be looking for in the documentation and forums.
Thanks,
Paul.
Dynamically Change a Page's Template Association
Re: Dynamically Change a Page's Template Association
What I really need is the variable name that holds the reference to the page's current template.
Then I will be able to change the value myself with some custom PHP code.
Thanks,
Paul.
Then I will be able to change the value myself with some custom PHP code.
Thanks,
Paul.
Re: Dynamically Change a Page's Template Association
You could use CSS to do this...
@media screen and (max-width: 650px) {
@media screen and (max-width: 650px) {
Re: Dynamically Change a Page's Template Association
Thankyou for your reply.
But using media queries will not solve the problem. We need to change the template that "surrounds" the content.
But using media queries will not solve the problem. We need to change the template that "surrounds" the content.
Re: Dynamically Change a Page's Template Association
Use one template, check for a variable like $mobile and switch content of template itself.
It's an old post but you might get the idea:
http://www.i-do-this.com/blog/14/Make-y ... bile-ready
It's an old post but you might get the idea:
http://www.i-do-this.com/blog/14/Make-y ... bile-ready
Re: Dynamically Change a Page's Template Association
Thank you uniqu3. I actually already have a script I wrote that returns a global variable $Platform, which is either "Mobile", "Facebook" or "Desktop".
What I need to figure out is how to change the template (template_id) of the page object before the rendering is done.
You'll have to excuse me but I am new to this PHP stuff, I come from an extensive .NET background.
Thanks,
Paul.
What I need to figure out is how to change the template (template_id) of the page object before the rendering is done.
You'll have to excuse me but I am new to this PHP stuff, I come from an extensive .NET background.
Thanks,
Paul.
Re: Dynamically Change a Page's Template Association
Don't change the template or anything. Just make ONE template, that contains both the mobile and desktop template and use an {if} statement to show either the one or the other.
If you want to keep everything tidy you might want to make two content blocks containing the "templates" and just load the right content block into your single main template.
If you want to keep everything tidy you might want to make two content blocks containing the "templates" and just load the right content block into your single main template.
Re: Dynamically Change a Page's Template Association
Thank you McDavid, but the client is will be adding new templates and content to the exisiting site. We don't trust them enough to use Smary logic.
What I want to do is make my own module that they can use which just keeps a list of template pairs, one for desktop and one for mobile.
Thanks,
Paul.
What I want to do is make my own module that they can use which just keeps a list of template pairs, one for desktop and one for mobile.
Thanks,
Paul.
Re: Dynamically Change a Page's Template Association
Well... most modules use their own templates/template db if their contents may potentially need any kind of formatting. If you take a look at News, CGBlog, Gallery, etc... (there is a huge number of modules that produce contents) you will see that a module can manage its own templates.paul wrote:What I want to do is make my own module that they can use which just keeps a list of template pairs, one for desktop and one for mobile.
On the other hand I'm not sure if that is the best solution...
However... you could use Smarty logic on the Main template (restricted to you, the developer) and call your module templates with a tag such as {yourmodule template='selectedtemplate'}...
This tag could be called inside {if} logic...
Just an idea though...
"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!
* 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!
Re: Dynamically Change a Page's Template Association
or just tell your client he can edit the templates in GCB's