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?
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
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?
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.
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.
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
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?
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?