Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Multiple templates per document View modes: 
User avatar
Member
Member
lancetek - 9/7/2011 7:49:12 AM
   
Multiple templates per document
Is there a way to use multiple templates per document? We are making a site and a sub-site (Mobile) and want them to share their Articles, but want a different look and feel for each site.

In the Cms desk the template dropdown only allows a single choice. I'm wondering if I can override the render programatically in the Mobile site to force a different template? If this is possible, could someone provide some code or a link to code where this has been done?

I'm thinking that I can just use the default template for Articles, but then for AliasPaths that start with /Mobile% I can use a different template.

Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 9/11/2011 4:59:32 AM
   
RE:Multiple templates per document
Hello,

One document can have just one page template. If you set programmatically a different page template when you approaches the page with a mobile device, it will be changed on the server side and thus for all other users (regardless the device). I guess this would cause huge problems e.g. after a post back when the page is not refreshed completelly.

Therefore, I would consider the following two approaches:

1) Having just one page template per document with doubled web parts where each of the two will show its content for particular device (normal/mobile). This can be achieved by a custom macro in the Visible property of a web part. An example with this concept can be found here: http://devnet.kentico.com/FAQs/Web-parts---Controls/How-to-show-hide-webpart-on-specific-document-with.aspx

2) On the contrary, you could take advantage of the two templates approach assigned to different documents. This would fit the scenario where the mobile web site is located on different site section (i.e. as another part of the content tree). This way you can modify your page templates separately with completely different look and feel.

Hope I got your point and shed some light.

Best regards
Ondrej Vasil




User avatar
Member
Member
lancetek - 9/11/2011 5:51:18 AM
   
RE:Multiple templates per document
Hi,
Thanks for the reply. We are trying to avoid duplicating content - we have thousands of 'stories' and don't want to have to create two different documents for each story.

So we've gone an imported the stories into the 'Article' document type, and are looking for a way to reuse the content easily, without duplicating it - creating two documents requires twice the effort of creating one.

Your suggestions are excellent, but I don't think they are suitable for our scenaio; here's why:

#1 - interesting, but we'd have to redesign the entire site. Quite a bit of extra work.
- each 'template' would inherit everything from the masterpage - we don't want the mobile site to have the burden of all of the css and js and other assets. I know we could pull out all the css and put them in the great 'head html' web parts and hide them selectively.
- Maybe if I would have thought about this eariler, I could have partitioned the template regions differently.

#2 - Means we need to duplicate the content.

So either way means extra work; #1 - we do a bunch of redesigning the zones and regions and #2 means duplicating content.

I am intrigued by #1 and seeing if I could get it to work - we have a 'mobile' heirarchy:


home
news
mobile
->/news
->/stories
->/etc...
events
etc...


So the mobile users will be directed to /mobile, and if we use #1, the content will actually be somewhere else in the tree, so I guess we'd use 'linked' documents with custom Document Aliases.

Hmmm, I just had another idea about #2 and how to get it to work for us - if we have two document types (as you suggest):

Article
mobileArticle

Then we can apply a unique template to each. If I make the mobileArticle type only have a single field of 'parentArticle' (that points to the original Article), I can use some Macro and Query magic to pull the information from the Article to display it in the mobileArticle transformation!

This would give us the ability of having different templates and layouts without having to deeply redesign the existing site.

Thanks for helping me work through this!
Lance

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 9/14/2011 4:19:21 AM
   
RE:Multiple templates per document
Hello,

Yes, this is good point with two document types. You can put the document selector into the mobileArticle doc type in order to be able to select document. This will give you the NodeGUID information for each document you select. Then you can develop a custom function to transformation which retrieves appropriate information for listed document(s).

Have a nice day.

Best regards
Ondrej Vasil