Try our conversational search powered by Generative AI!

How to create content based on same PageData different Template?

Vote:
 

The current learning is limited to different PageDate corresponding to the specified Template. But I would like to create two groups of content, based on the same PageData, different Template, how can I do?

#139402
Oct 01, 2015 14:23
Vote:
 

Hi Gary,

What rules/scenarios do you have to determine where it's should be Template A or Template B?

Different templates for different visitors?

#139412
Oct 01, 2015 16:38
Vote:
 

Thank you for your reply, this time has been busy with other things, failed to follow up in time.

Because of some reasons, can not use the response layout, only for different terminals, making different Template, but the content of the same PageDate.  

So want to consult, how to use a different Template in the same PageData

#140601
Oct 24, 2015 4:24
Vote:
 

I understand what you mean, to give a good suggestion I need to know what rules you have to define this template?

Just go give a few examples:
DIfferent time of day? Visits from different countries? Different page types? Same page type but different content on each page? Something specific on the user such as roles?

#140603
Oct 24, 2015 10:25
Vote:
 

You may look at TemplateResolver class, and particularly at TemplateResolved event. This extension hook may give you possibility to override chosen template for the page type.

#140609
Oct 25, 2015 8:29
Vote:
 

Ah, I think I found a simple way.
Usually, a PageController contains only one default Action, for example:

……
ActionResult Index public (currentPage StandardPage)
{
View return (currentPage);
}
……

I added other Action, such as:

……
ActionResult Mobile public (currentPage StandardPage)
{
    return ("Mobile", currentPage);
}
ActionResult Pad public (currentPage StandardPage)
{
    return ("Pad", currentPage);
}
……

And then in Views, set different Views set different parant Layout.
When accessing a content, such as:

http://localhost/product/detail-1, display the default Template style,

access http://localhost/product/detail-1/Mobile is, display mobile style,

and so on.

#140695
Oct 28, 2015 2:43
Vote:
 

Take a look at this section of the documentation as well

http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/9/Rendering/Rendering/

Then you could write like this:

[TemplateDescriptor(Tags = new string[] { RenderingTags.Mobile })]
public partial class MyPageMobileTemplate : TemplatePage<MyPage> { }

[TemplateDescriptor(Inherited = true)]
public partial class MyFallbackTemplate : TemplatePage<PageData> { }

And in that example the first controller will take care of your mobile view
 

#140696
Oct 28, 2015 7:26
Vote:
 

Great that you found a solution.

Just to check I've got some further questions.

Do you plan to link to the mobile version inside EPiServer?

Do you plan that mobile devices automatically should come to this view when linked to or browsed to the page?

#140698
Oct 28, 2015 7:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.