Class Template
Represents a Template file.
Namespace: Umbraco.Cms.Core.Models
Assembly: Umbraco.Core.dll
Syntax
[DataContract(IsReference = true)]
public class Template : File, ITemplate, IFile, IEntity, IDeepCloneable, IRememberBeingDirty, ICanBeDirty
Constructors
View SourceTemplate(IShortStringHelper, string?, string?)
Initializes a new instance of the Template class.
Declaration
public Template(IShortStringHelper shortStringHelper, string? name, string? alias)
Parameters
| Type | Name | Description |
|---|---|---|
| IShortStringHelper | shortStringHelper | The short string helper for alias cleaning. |
| string | name | The name of the template. |
| string | alias | The alias of the template. |
Template(IShortStringHelper, string?, string?, Func<File, string?>?)
Initializes a new instance of the Template class.
Declaration
public Template(IShortStringHelper shortStringHelper, string? name, string? alias, Func<File, string?>? getFileContent)
Parameters
| Type | Name | Description |
|---|---|---|
| IShortStringHelper | shortStringHelper | The short string helper for alias cleaning. |
| string | name | The name of the template. |
| string | alias | The alias of the template. |
| Func<File, string> | getFileContent | A function to retrieve the file content lazily. |
Properties
View SourceAlias
Gets or sets the alias of the template.
Declaration
[DataMember]
public string Alias { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The alias is automatically cleaned using the underscore alias format.
IsMasterTemplate
Returns true if the template is used as a layout for other templates (i.e. it has 'children')
Declaration
public bool IsMasterTemplate { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
MasterTemplateAlias
Gets or sets the alias of the master (parent) template.
Declaration
public string? MasterTemplateAlias { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The alias of the master template, or |
MasterTemplateId
Gets or sets the master template identifier as a lazy-loaded value.
Declaration
[DataMember]
public Lazy<int>? MasterTemplateId { get; set; }
Property Value
| Type | Description |
|---|---|
| Lazy<int> | A System.Lazy<T> containing the master template's ID, or -1 if there is no master template. |
Name
Gets or sets the name of the template.
Declaration
[DataMember]
public string? Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
View SourceDeepCloneNameAndAlias(File)
Overrides the base implementation to prevent File from cloning name and alias.
Declaration
protected override void DeepCloneNameAndAlias(File clone)
Parameters
| Type | Name | Description |
|---|---|---|
| File | clone | The cloned file instance. |
SetMasterTemplate(ITemplate?)
Sets the master template for this template.
Declaration
[Obsolete("MasterTemplate is now calculated from the content. Scheduled for removal in Umbraco 18.")]
public void SetMasterTemplate(ITemplate? masterTemplate)
Parameters
| Type | Name | Description |
|---|---|---|
| ITemplate | masterTemplate | The master template to set, or |