Hi,
You could try to use TemplateResolver:
http://world.episerver.com/documentation/Class-library/?documentId=cms/7/159e1a69-8fa7-aaac-d12c-f72b5170a30a
Hello, thank you for your suggestion, could u provide an example with it? i never worked with it and have to clue where everything links together.
Hi,
First create InitializationModule and subscribe to TemplateResolved event. Inside TemplateResolved method you should determinate the current domain. Based on that information you could select proper template.
using System; using System.Linq; using System.Web; using EPiServer.Framework; using EPiServer.Framework.Initialization; using EPiServer.Web; using EpiServerThumbnail.Models.Pages; namespace EpiServerThumbnail.Business { [InitializableModule] public class MobileRedirectSample : IInitializableModule { public void Initialize(InitializationEngine context) { context.Locate.TemplateResolver().TemplateResolved += new EventHandler<TemplateResolverEventArgs>(this.HomePageTemplateResolved); } public void Uninitialize(global::EPiServer.Framework.Initialization.InitializationEngine context) { context.Locate.TemplateResolver().TemplateResolved -= new EventHandler<TemplateResolverEventArgs>(this.HomePageTemplateResolved); } void HomePageTemplateResolved(object sender, TemplateResolverEventArgs eventArgs) { if (eventArgs.ItemToRender != null && eventArgs.ItemToRender is ProductPage) { var templateName = IsSite1(eventArgs) ? "Site1" : "Site2"; var render = eventArgs.SupportedTemplates.SingleOrDefault( r => r.Name == templateName && r.TemplateTypeCategory == eventArgs.SelectedTemplate.TemplateTypeCategory); if (render != null) { eventArgs.SelectedTemplate = render; } } } private bool IsSite1(TemplateResolverEventArgs eventArgs) { // determinate is this is site1 or site2 return eventArgs.WebContext.Request.ServerVariables["SERVER_NAME"] == "Site1.com"; } public void Preload(string[] parameters) { } } }
Then you need two renderers one for Site1 and second for Site2.
For ASP Webforms:
[TemplateDescriptor(Tags = new[] { "Site1" })] public partial class HomePage1Template : TemplatePageBase<ProductPage> { } [TemplateDescriptor(Tags = new[] { "Site2" })] public partial class HomePage2Template : TemplatePageBase<ProductPage> { }
For ASP MVC:
[TemplateDescriptor( Inherited = true, TemplateTypeCategory = TemplateTypeCategories.MvcController, Tags = new[] { "Site1"}, Default = true, AvailableWithoutTag = true)] public class Site1HomePageController : PageController<PageData> { public ActionResult Index(PageData currentPage) { } } [TemplateDescriptor( Inherited = true, TemplateTypeCategory = TemplateTypeCategories.MvcController, Tags = new[] { "Site2"}, Default = true, AvailableWithoutTag = true)] public class Site2HomePageController : PageController<PageData> { public ActionResult Index(PageData currentPage) { } }
You could also try to use Display Channels (instead of TemplateResolver).
public class MobileDisplayChannel : DisplayChannel { public override bool IsActive(HttpContextBase context) { return context.Request.ServerVariables["SERVER_NAME"] == "Site1.com"; } public override string ChannelName { get { return RenderingTags.Mobile; } } }
The code above is just a draft. I didn't test it.
Hello,i am developing a multi site and want to use the same HomePage page type for each of the sites with different page templates. Is there any way of creating this or do i need to duplicate the page types?. The page types we use are the same with the same properties so i dont really want to duplicate them if i have the option of using the same for 2 templates.
thanks, Andrei