Interface ITemplatePathResolver
Interface to resolve template path for the requested render type
Namespace: EPiServer.Web
Assembly: EPiServer.dll
Version: 10.10.4Syntax
public interface ITemplatePathResolverExamples
  The following code example demonstrates how to create a template path resolver.
public class FlattenTemplatePathResolverSample : ITemplatePathResolver,  IInitializableModule, IConfigurableModule
{
public FlattenTemplatePathResolverSample()
: this("TemplatePath")
{ 
}
public FlattenTemplatePathResolverSample(string physicalBasePath)
{
PhysicalBasePath = physicalBasePath;
}
public event EventHandler<ResolvingTemplatePathEventArgs> ResolvingTemplatePath;
/// <summary>
/// Gets or sets the physical base path, where all templates .
/// </summary>
public string PhysicalBasePath
{
get;
set;
}
/// <summary>
/// Resolves the path for the requested render type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="typeOfTemplate">The type of template.</param>
/// <returns>
/// returns path to the control
/// </returns>
public string ResolvePath(Type type, TemplateTypeCategories typeOfTemplate)
{
if (ResolvingTemplatePath != null)
{
    var e = new ResolvingTemplatePathEventArgs(type, typeOfTemplate);
    ResolvingTemplatePath(this, e);
    if (!String.IsNullOrEmpty(e.Path))
    {
        return e.Path;
    }
}
string extension;
switch (typeOfTemplate)
{
    case TemplateTypeCategories.WebFormsPage:
        extension = "aspx";
        break;
    case TemplateTypeCategories.UserControl:
        extension = "ascx";
        break;
    default:
        throw new NotSupportedException();
}
return String.Format(CultureInfo.InvariantCulture, "~/{0}/{1}.{2}", PhysicalBasePath, type.Name, extension);
}
/// <summary>
/// Sets the FlattenTemplatePathResolverSample to default ITemplatePathResolver
/// </summary>
/// <param name="context">The context.</param>
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Container.Configure(ce =>
{
    ce.For<ITemplatePathResolver>().Use<FlattenTemplatePathResolverSample>();
});
}
public void Initialize(InitializationEngine context)
{
}
public void Preload(string[] parameters)
{
}
public void Uninitialize(InitializationEngine context)
{
}
}Methods
ResolvePath(Type, TemplateTypeCategories)
Resolves the path for the requested render type.
Declaration
string ResolvePath(Type type, TemplateTypeCategories templateTypeCategory)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Type | type | The type. | 
| TemplateTypeCategories | templateTypeCategory | The type of template. | 
Returns
| Type | Description | 
|---|---|
| System.String | returns path to the control | 
Events
ResolvingTemplatePath
Occurs when tries to resolve template path.
Declaration
event EventHandler<ResolvingTemplatePathEventArgs> ResolvingTemplatePathEvent Type
| Type | Description | 
|---|---|
| System.EventHandler<ResolvingTemplatePathEventArgs> | 
