SaaS CMS has officially launched! Learn more now.
AI OnAI Off
SaaS CMS has officially launched! Learn more now.
Hi,
You can hook up to the TemplateResolved event of the TemplateResolver. One way to do it is in an initialization module:
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))] [InitializableModule] public class TemplateInitialization : IInitializableModule { public void Initialize(InitializationEngine context) { context.Locate.TemplateResolver().TemplateResolved += OnTemplateResolved; } public void Uninitialize(InitializationEngine context) { ServiceLocator.Current.GetInstance<TemplateResolver>().TemplateResolved -= OnTemplateResolved; } public void Preload(string[] parameters) { } static void OnTemplateResolved(object sender, TemplateResolverEventArgs args) { var myContent = args.ItemToRender as YourPageType; if (myContent != null) { IEnumerable<TemplateModel> supportedTemplates = args.SupportedTemplates; // Should contain your three templates // Set template based on condition if (...) { args.SelectedTemplate = supportedTemplates.FirstOrDefault(...); } } } }
Hi,
I have one pagetype.For that I have set three templates.In Admin mode,When I create a page it takes the default template.I need to choose an alternate from the three.How can i choose it dynamically?