Class TemplatePathResolver
The TemplatePathResolver resolves path to the requested render type.
Inheritance
System.Object
TemplatePathResolver
Implements
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Web
Assembly: EPiServer.dll
Version: 9.12.2Syntax
[ServiceConfiguration(typeof(ITemplatePathResolver), Lifecycle = ServiceInstanceScope.Singleton)]
public class TemplatePathResolver : ITemplatePathResolver
Examples
The following code example demonstrates how to exchange the template path for requests.
public class TemplatePathResolverSample : IInitializableModule
{
public TemplatePathResolverSample()
: this("TemplatePath")
{
}
public TemplatePathResolverSample(string physicalBasePath)
{
PhysicalBasePath = physicalBasePath;
}
/// <summary>
/// Starts to listen on ResolvingTemplatePath event
/// </summary>
/// <param name="context">The context.</param>
public void Initialize(InitializationEngine context)
{
context.Locate.TemplatePathResolver().ResolvingTemplatePath += TemplatePathResolverSample_ResolvingTemplatePath;
}
public void Preload(string[] parameters)
{
}
public void Uninitialize(InitializationEngine context)
{
context.Locate.TemplatePathResolver().ResolvingTemplatePath -= TemplatePathResolverSample_ResolvingTemplatePath;
}
/// <summary>
/// Gets or sets the physical base path, where all templates .
/// </summary>
public string PhysicalBasePath
{
get;
set;
}
private void TemplatePathResolverSample_ResolvingTemplatePath(object sender, ResolvingTemplatePathEventArgs e)
{
string extension;
switch (e.Category)
{
case TemplateTypeCategories.WebFormsPage:
extension = "aspx";
break;
case TemplateTypeCategories.UserControl:
extension = "ascx";
break;
default:
throw new NotSupportedException();
}
e.Path = String.Format(CultureInfo.InvariantCulture, "~/{0}/{1}.{2}", PhysicalBasePath, e.Type.Name, extension);
}
}
Constructors
TemplatePathResolver(IHostingEnvironment, IModuleResourceResolver)
Initializes a new instance of the ResolvingTemplatePath class.
Declaration
public TemplatePathResolver(IHostingEnvironment hostingEnvironment, IModuleResourceResolver resourcePathResolver)
Parameters
Type | Name | Description |
---|---|---|
IHostingEnvironment | hostingEnvironment | The hosting environment. |
IModuleResourceResolver | resourcePathResolver | The resource path resolv |
TemplatePathResolver(IHostingEnvironment, ModuleTable)
Initializes a new instance of the ResolvingTemplatePath class.
Declaration
[Obsolete("Use alternative constructor")]
public TemplatePathResolver(IHostingEnvironment hostingEnvironment, ModuleTable moduleTable)
Parameters
Type | Name | Description |
---|---|---|
IHostingEnvironment | hostingEnvironment | The hosting environment. |
ModuleTable | moduleTable | The Shell module table. |
Methods
ResolvePath(Type, TemplateTypeCategories)
Resolves the path for the requested render type.
Declaration
public virtual string ResolvePath(Type type, TemplateTypeCategories templateTypeCategory)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The render type. |
TemplateTypeCategories | templateTypeCategory | The type of template. |
Returns
Type | Description |
---|---|
System.String | returns path to the render template. |
Remarks
The ResolvePath resolves path by following order
- Resolves path by raising ResolvingTemplatePath event
- Resolves path from root of application according to namespace e.g. if the namespace is like A.B.C and the typename is X then the searching paths are (~/A/B/C/X, ~/B/C/X, ~/C/X, ~/X)
- Resolves path from root of corresponding Shell module according to namespace e.g. if the namespace is like A.B.C, typename is X and the Shell module path is M then the searching paths are (~/M/A/B/C/X, ~/M/B/C/X, ~/M/C/X, ~/M/X)
ResolvePath(Type, String, String)
Creates the path from namespace.
Declaration
protected virtual string ResolvePath(Type type, string basePath, string extension)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
System.String | basePath | The base path. |
System.String | extension | The extension. |
Returns
Type | Description |
---|---|
System.String |
ResolvePathByTypeOfTemplate(Type, String, TemplateTypeCategories)
Resolves the path by type of template.
Declaration
protected virtual string ResolvePathByTypeOfTemplate(Type type, string basePath, TemplateTypeCategories templateTypeCategory)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
System.String | basePath | The base path. |
TemplateTypeCategories | templateTypeCategory | The type of template. |
Returns
Type | Description |
---|---|
System.String |
Events
ResolvingTemplatePath
Occurs when [template path resolver event].
Declaration
public event EventHandler<ResolvingTemplatePathEventArgs> ResolvingTemplatePath
Event Type
Type | Description |
---|---|
System.EventHandler<ResolvingTemplatePathEventArgs> |