SaaS CMS has officially launched! Learn more now.

Class TemplateOptions

Provides access to configure cms template system.

Inheritance
System.Object
TemplateOptions
Namespace: EPiServer.Web.Templating
Assembly: EPiServer.Cms.AspNetCore.Templating.dll
Version: 12.0.3
Syntax
[Options(ConfigurationSection = "Cms")]
public class TemplateOptions : Object

Constructors

TemplateOptions()

Declaration
public TemplateOptions()

Properties

RegisterFakeTemplate

Register a fake template for use when external templates is used

Declaration
public bool RegisterFakeTemplate { get; set; }
Property Value
Type Description
System.Boolean

ScanViewsForTemplateRegistration

Scan views for template registration.

Declaration
public bool ScanViewsForTemplateRegistration { get; set; }
Property Value
Type Description
System.Boolean
Remarks

By default the system will scan for views. Set to false to disable.

TemplateAssemblies

The assemblies that is scanned for templates.

Declaration
public IList<Assembly> TemplateAssemblies { get; }
Property Value
Type Description
System.Collections.Generic.IList<System.Reflection.Assembly>
Remarks

By default it is the assembly calling AddCms and the builtin templates.

Methods

AddAssemblyTemplates<TTypeInAssembly>()

Registers templates found in assembly specified by type.

Declaration
public TemplateOptions AddAssemblyTemplates<TTypeInAssembly>()
Returns
Type Description
TemplateOptions
Type Parameters
Name Description
TTypeInAssembly

Type in the assembly that should be scanned for templates.

Remarks

A registered template will be used before a builtin template registered in .

AddPartialView<T>(Boolean, String[])

Registers a partial view named as typeof(T).Name as a template for instances of T

Declaration
public TemplateOptions AddPartialView<T>(bool inherit, params string[] templateTags)
Parameters
Type Name Description
System.Boolean inherit

Specifies it htis template should be available for types inheriting T

System.String[] templateTags

The template tags for which the template is registered

Returns
Type Description
TemplateOptions
Type Parameters
Name Description
T

The modeltype that the partial view supports

Remarks

The default convention is that if the T is an abstract type or interface then the partial view is available for all implementations. If the type is a concrete type then the partial view is only registered for T. To get another behaviour you can use the overload where inherit is specified explicitly.

Another convention is that if templateTags is specified then the template is registered as available only when some of the template tags are present. To get another behaviour you can use AddTemplate(TemplateModel) where AvailableWithoutTag can be used to specify the behaviour.

AddPartialView<T>(String, Boolean, String[])

Registers a partial view as a template for instances of T

Declaration
public TemplateOptions AddPartialView<T>(string partialName, bool inherit, params string[] templateTags)
Parameters
Type Name Description
System.String partialName

The name of the partial view. If null it registers a partial view with the same name as the T

System.Boolean inherit

Specifies explicitly if template should be available to sub types.

System.String[] templateTags

The template tags for which the template is registered

Returns
Type Description
TemplateOptions
Type Parameters
Name Description
T

The modeltype that the partial view supports

Remarks

A convention is that if templateTags is specified then the template is registered as available only when some of the template tags are present. To get another behaviour you can use AddTemplate(TemplateModel) where AvailableWithoutTag can be used to specify the behaviour.

AddPartialView<T>(String, String[])

Registers a partial view as a template for instances of T

Declaration
public TemplateOptions AddPartialView<T>(string partialName, params string[] templateTags)
Parameters
Type Name Description
System.String partialName

The name of the partial view. If null it registers a partial view with the same name as the T

System.String[] templateTags

The template tags for which the template is registered

Returns
Type Description
TemplateOptions
Type Parameters
Name Description
T

The modeltype that the partial view supports

Remarks

The default convention is that if the T is an abstract type or interface then the partial view is available for all implementations. If the type is a concrete type then the partial view is only registered for T. To get another behaviour you can use the overload where inherit is specified explicitly.

Another convention is that if templateTags is specified then the template is registered as available only when some of the template tags are present. To get another behaviour you can use AddTemplate(TemplateModel) where AvailableWithoutTag can be used to specify the behaviour.

AddPartialView<T>(String[])

Registers a partial view as a template for instances of T

Declaration
public TemplateOptions AddPartialView<T>(params string[] templateTags)
Parameters
Type Name Description
System.String[] templateTags

The template tags for which the template is registered

Returns
Type Description
TemplateOptions
Type Parameters
Name Description
T

The modeltype that the partial view supports

Remarks

The default convention is that if the T is an abstract type or interface then the partial view is available for all implementations. If the type is a concrete type then the partial view is only registered for T. To get another behaviour you can use the overload where inherit is specified explicitly.

Another convention is that if templateTags is specified then the template is registered as available only when some of the template tags are present. To get another behaviour you can use AddTemplate(TemplateModel) where AvailableWithoutTag can be used to specify the behaviour.

AddTemplate(TemplateModel)

Registers a template to be used during rendering.

Declaration
public TemplateOptions AddTemplate(TemplateModel templateModel)
Parameters
Type Name Description
TemplateModel templateModel

The template model to register

Returns
Type Description
TemplateOptions

AddTemplate<T>()

Registers a template T as a template.

Declaration
public TemplateOptions AddTemplate<T>()
    where T : IRenderTemplate
Returns
Type Description
TemplateOptions
Type Parameters
Name Description
T

The type of template

Remarks

The template type can be decorated with TemplateDescriptorAttribute to restrict in which contexts the template should be available.

ConfigureForExternalTemplates()

Configures routing and templating to support that templates are deployed in a separate application

Declaration
public void ConfigureForExternalTemplates()

Extension Methods