• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Dynamically Change a Page's Template Association
PostPosted: Thu Apr 05, 2012 9:41 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 16, 2010 9:54 pm
Posts: 21
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.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Thu Apr 05, 2012 9:48 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 16, 2010 9:54 pm
Posts: 21
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.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Thu Apr 05, 2012 10:49 pm 
Offline
Administrator
Administrator
User avatar

Joined: Thu Mar 09, 2006 5:32 am
Posts: 11866
Location: Arizona
You could use CSS to do this...

@media screen and (max-width: 650px) {

_________________
Extensions » Modules/Tags click the name of the module/tag or Help to the right to get its parameters.
Right click and view source is a great way to see what you have to work with.
Check ver. CMSMS, PHP, server OS, in System Information page.
Default content http://multiintech.com/defaultcontent/
People are Wonderful
Business is Great
Life is Terrific
Ever wonder what happened to the Album module? Well it is alive and well.
http://album.multiintech.com/
Image


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Thu Apr 05, 2012 10:53 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 16, 2010 9:54 pm
Posts: 21
Thankyou for your reply.

But using media queries will not solve the problem. We need to change the template that "surrounds" the content.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Fri Apr 06, 2012 6:17 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 1984
Location: Feldkirchen in Kärnten, Austria
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

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Mon Apr 09, 2012 4:48 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 16, 2010 9:54 pm
Posts: 21
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.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Mon Apr 09, 2012 8:24 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Mar 31, 2009 8:45 pm
Posts: 377
Location: Delft, Netherlands
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.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Mon Apr 09, 2012 8:30 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 16, 2010 9:54 pm
Posts: 21
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.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Mon Apr 09, 2012 9:12 pm 
Offline
Power Poster
Power Poster

Joined: Mon Jan 29, 2007 4:47 pm
Posts: 426
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.
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.
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...).

My developer Page on the Forge.


Top
 Profile  
 
 Post subject: Re: Dynamically Change a Page's Template Association
PostPosted: Tue Apr 10, 2012 8:01 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Mar 31, 2009 8:45 pm
Posts: 377
Location: Delft, Netherlands
or just tell your client he can edit the templates in GCB's


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner