Class TemplatePathResolver
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. The TemplatePathResolver resolves path to the requested render type.
Inheritance
Implements
Inherited Members
Namespace: EPiServer.Web.Internal
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7Syntax
[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)
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. Creates a new instance of TemplatePathResolver
Declaration
public TemplatePathResolver(IHostingEnvironment hostingEnvironment, IModuleResourceResolver resourcePathResolver)
Parameters
Type | Name | Description |
---|---|---|
IHostingEnvironment | hostingEnvironment | |
IModuleResourceResolver | resourcePathResolver |
Methods
ResolvePath(Type, TemplateTypeCategories)
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. 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)
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. 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)
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. 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
Unsupported INTERNAL API! Not covered by semantic versioning; might change without notice. Occurs when [template path resolver event].
Declaration
public event EventHandler<ResolvingTemplatePathEventArgs> ResolvingTemplatePath
Event Type
Type | Description |
---|---|
System.EventHandler<ResolvingTemplatePathEventArgs> |