Interface ITemplateResolverEvents
Exposes events raised during template resolving through ITemplateResolver that can be used to extend template resolving.
Namespace: EPiServer.Web
Assembly: EPiServer.dll
Version: 9.12.2Syntax
public interface ITemplateResolverEvents
Events
TemplateResolved
Occurs when tries to resolve control. This events raises after finding default or first supported template. One can change the selected template on the TemplateResolverEventArgs
Declaration
event EventHandler<TemplateResolverEventArgs> TemplateResolved
Event Type
Type | Description |
---|---|
System.EventHandler<TemplateResolverEventArgs> |
Examples
The following code example demonstrates how to exchange the template for mobile requests.
[InitializableModule]
public class MobileRedirectSample : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
context.Locate.TemplateResolver().TemplateResolved
+= new EventHandler<TemplateResolverEventArgs>(MobileRedirectSample_TemplateResolved);
}
public void Uninitialize(global::EPiServer.Framework.Initialization.InitializationEngine context)
{
context.Locate.TemplateResolver().TemplateResolved
-= new EventHandler<TemplateResolverEventArgs>(MobileRedirectSample_TemplateResolved);
}
void MobileRedirectSample_TemplateResolved(object sender, TemplateResolverEventArgs eventArgs)
{
if (eventArgs.ItemToRender != null && eventArgs.ItemToRender is TypedPage &&
HttpContext.Current.Request.Browser.IsMobileDevice)
{
var mobileRender = eventArgs.SupportedTemplates
.SingleOrDefault(r => r.Name.Contains("Mobile") &&
r.TemplateTypeCategory == eventArgs.SelectedTemplate.TemplateTypeCategory);
if (mobileRender != null)
{
eventArgs.SelectedTemplate = mobileRender;
}
}
}
public void Preload(string[] parameters)
{
}
}
TemplateResolving
Occurs when a template is about to be resolved.
Declaration
event EventHandler<TemplateResolverEventArgs> TemplateResolving
Event Type
Type | Description |
---|---|
System.EventHandler<TemplateResolverEventArgs> |
Remarks
If an eventHandler sets the TemplateModel on the eventargs to the event then that render is used without calling for registered renderers.