London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
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?