Skip to content

Templates (OrchardCore.Templates)

模板(OrchardCore.Templates

The templates module allows editors to create custom Liquid templates.

模板模块允许编辑者创建自定义Liquid模板。

Available templates

可用模板

Templates can be defined using the web editor, or in a theme. Templates are distinguished by their name.

可以使用Web编辑器或主题定义模板。模板以其名称区分。

Orchard Core doesn't render HTML directly, but instead will usually render something called a Shape, which is an object that represents

Orchard Core不直接呈现HTML,而是通常会呈现一个名为 Shape 的东西,它是一个代表的对象

the thing to render and has all the necessary data and metatada to render HTML.

要呈现的东西,并具有呈现HTML的所有必要数据和元数据。

When rendering a Shape, Orchard Core will look for specific templates, passing the Shape to this template.

渲染Shape时,Orchard Core将查找特定模板,将Shape传递给此模板。

Orchard Core can match with many templates for the same Shape.

Orchard Core可以匹配相同Shape的许多模板。

These potential templates are called Alternates.

这些潜在的模板称为 Alternates

A Shape contains a list of acceptable template names (the alternates) and will look into providers to get the most appropriate one.

Shape包含可接受的模板名称列表(替换项),并将查找提供程序以获取最合适的模板名称。

For instance, when rendering a Content Item of type Article, the corresponding Shape that is rendered will be configured

例如,在呈现Article类型的Content Item时,将配置渲染的相应Shape

to look for a template that handles all articles, but also one that handles an article when used in a list, and so on.

查找处理所有文章的模板,以及在列表中使用时处理文章的模板,依此类推。

This document provides a list of pre-defined templates that can be used when rendering shapes.

本文档提供了在渲染形状时可以使用的预定义模板列表。

It uses the internal name of a template and also the filename in case it's provided by a Theme.

它使用模板的内部名称以及文件名,以防主题提供。

Content templates

内容模板

Content__[ContentType]

内容__ [ContentType的]

This template is called when displaying a content item with the Detail display type, for instance when accessed from its own URL.

当显示具有“Detail”显示类型的内容项时,例如当从其自己的URL访问时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Content__BlogPost | Content-BlogPost.cshtml |

| Content__BlogPost | Content-BlogPost.cshtml |

| Content__Article | Content-Article.cshtml |

| Content__Article | Content-Article.cshtml |

Available properties

可用的属性

| Property | Description |

|财产|说明|

| --------- | ------------ |

| --------- | ------------ |

| Model.Content | A zone shape that contains all the shapes generated by the content's parts and fields. |

| Model.Content |包含内容部件和字段生成的所有形状的区域形状。 |

| Model.ContentItem | Represents the current content item being rendered by the template. |

| Model.ContentItem |表示模板呈现的当前内容项。 |

| Model.ContentItem.Content | A Json object containing all the data of the content item. |

| Model.ContentItem.Content |包含内容项的所有数据的Json对象。 |

Content_[DisplayType]__[ContentType]

Content_ [显示类型] __ [ContentType的]

This template is called when displaying a content item with a specific display type.

显示具有特定显示类型的内容项时,将调用此模板。

For instance, when a content item is displayed in a list, the Summary display type is commonly used.

例如,当在列表中显示内容项时,通常使用“摘要”显示类型。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Content_Summary__BlogPost | Content-BlogPost.Summary.cshtml |

| Content_Summary__BlogPost | Content-BlogPost.Summary.cshtml |

| Content_Summary__Article | Content-Article.Summary.cshtml |

| Content_Summary__Article | Content-Article.Summary.cshtml |

Widget templates

小部件模板

Widget__[ContentType]

的widget __ [ContentType的]

This template is called when a widget is rendered on a page.

在页面上呈现窗口小部件时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Widget__Paragraph | Widget-Paragraph.cshtml |

| Widget__Paragraph | Widget-Paragraph.cshtml |

| Widget__Blockquote | Widget-Blockquote.cshtml |

| Widget__Blockquote | Widget-Blockquote.cshtml |

Available properties

可用的属性

| Property | Description |

|财产|说明|

| --------- | ------------ |

| --------- | ------------ |

| Model.Content | A zone shape that contains all the shapes generated by the widget's parts and fields. |

| Model.Content |区域形状,包含窗口小部件的部件和字段生成的所有形状。 |

| Model.ContentItem | Represents the current content item being rendered by the template. |

| Model.ContentItem |表示模板呈现的当前内容项。 |

| Model.ContentItem.Content | A Json object containing all the data of the content item. |

| Model.ContentItem.Content |包含内容项的所有数据的Json对象。 |

| Model.Classes | An array of all the classes attached to the widget. |

| Model.Classes |附加到窗口小部件的所有类的数组。 |

Content Part templates

内容部分模板

Each driver is free to return a shape type of its choosing, but the usage is

每个驱动程序都可以自由返回其选择的形状类型,但用法是

to render a content part using a shape with a name that matches the type name.

使用名称与类型名称匹配的形状呈现内容部件。

For instance the HtmlBodyPart content part will return a single shape of type HtmlBodyPart, but the ListPart returns many

例如,HtmlBodyPart内容部分将返回一个类型为HtmlBodyPart的形状,但ListPart返回许多

shapes, one among them being ListPart.

形状,其中一个是ListPart

As a consequence the following list of templates use the [ShapeType] term where

因此,以下模板列表使用[ShapeType]术语where

most of the time it will be equal to the name of the content part. The examples use

大部分时间它将等于内容部分的名称。这些例子使用

common content part names for this reason.

因此,共同内容部分名称。

Properties

属性

The properties available on a shape rendered for a content part are unique for each content

为内容部件呈现的形状上可用的属性对于每个内容都是唯一的

part. Please refer to each content part documentation.

部分。请参阅每个内容部分文档。

[ShapeType]

[ShapeType]

This template is called when a Content Part is rendered.

呈现内容部件时调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| HtmlBodyPart | HtmlBodyPart.cshtml |

| HtmlBodyPart | HtmlBodyPart.cshtml |

| ListPartFeed | ListPartFeed.cshtml |

| ListPartFeed | ListPartFeed.cshtml |

[ShapeType]_[DisplayType]

[ShapeType] _ [显示类型]

This template is called when a Content Part shape type is rendered in a specific display type.

在特定显示类型中呈现内容部件形状类型时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| HtmlBodyPart_Summary | HtmlBodyPart.Summary.cshtml |

| HtmlBodyPart_Summary | HtmlBodyPart.Summary.cshtml |

[ContentType]_[DisplayType]__[PartType]

[ContentType的] _ [显示类型] __ [PartType]

This template is called when a content part type is rendered for a given content type, with or without a given display type.

在为给定内容类型呈现内容部件类型时调用此模板,具有或不具有给定的显示类型。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__HtmlBodyPart | Blog-HtmlBodyPart.cshtml |

| Blog__HtmlBodyPart | Blog-HtmlBodyPart.cshtml |

| LandingPage__BagPart | LandingPage-BagPart.cshtml |

| LandingPage__BagPart | LandingPage-BagPart.cshtml |

| Blog_Summary__HtmlBodyPart | Blog-HtmlBodyPart.Summary.cshtml |

| Blog_Summary__HtmlBodyPart | Blog-HtmlBodyPart.Summary.cshtml |

| LandingPage_Summary__BagPart | LandingPage-BagPart.Summary.cshtml |

| LandingPage_Summary__BagPart | LandingPage-BagPart.Summary.cshtml |

[ContentType]``_[DisplayType]__[PartName]

[ContentType的]``_ [显示类型] __ [零件名称]

This template is called when a content part name is rendered for a given content type, with or without a given display type.

在为给定内容类型呈现内容部件名称时,无论是否具有给定的显示类型,都会调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| LandingPage__Services | LandingPage-Services.cshtml |

| LandingPage__Services | LandingPage-Services.cshtml |

| LandingPage_Summary__Services | LandingPage-Services.Summary.cshtml |

| LandingPage_Summary__Services | LandingPage-Services.Summary.cshtml |

[ContentType]_[DisplayType]__[PartType]__[ShapeType]

[ContentType的] _ [显示类型] __ [PartType] __ [ShapeType]

This template is called when a shape type is rendered in a given content part type for a given content type, with or without a given display type.

在给定内容类型的给定内容部件类型中呈现形状类型(具有或不具有给定显示类型)时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__ListPart__ListPartFeed | Blog__ListPart__ListPartFeed.cshtml |

| Blog__ListPart__ListPartFeed | Blog__ListPart__ListPartFeed.cshtml |

| Blog_Summary__ListPart__ListPartFeed | Blog__ListPart__ListPartFeed.Summary.cshtml |

| Blog_Summary__ListPart__ListPartFeed | Blog__ListPart__ListPartFeed.Summary.cshtml |

[ContentType]_[DisplayType]__[PartName]__[ShapeType]

[ContentType的] _ [显示类型] __ [零件名称] __ [ShapeType]

This template is called when a shape type is rendered in a given content part name for a given content type, with or without a given display type.

在给定内容类型的给定内容部件名称中呈现形状类型(具有或不具有给定显示类型)时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| LandingPage__Services__CustomShape | LandingPage-Services-CustomShape.cshtml |

| LandingPage__Services__CustomShape | LandingPage-Services-CustomShape.cshtml |

| LandingPage_Summary__Services__CustomShape | LandingPage-Services-CustomShape.Summary.cshtml |

| LandingPage_Summary__Services__CustomShape | LandingPage-Services-CustomShape.Summary.cshtml |

Content Field templates

内容字段模板

Each driver is free to return a shape type of its choosing but the usage is

每个驱动程序都可以自由返回其选择的形状类型,但用途是

to render a content field using a shape with the same type name.

使用具有相同类型名称的形状呈现内容字段。

For instance the TextField content field will return a single shape of type TextField,

例如,TextField内容字段将返回一个类型为TextField的形状,

but other fields might return many shapes.

但其他领域可能会返回许多形状。

Properties

属性

The properties available on a shape rendered for a content field are unique for each content

为内容字段呈现的形状上可用的属性对于每个内容都是唯一的

field. Please refer to each content field documentation.

领域。请参阅每个内容字段文档。

[ShapeType]_[DisplayType]

[ShapeType] _ [显示类型]

This template is called when a content field type is rendered in given display type.

在给定显示类型中呈现内容字段类型时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| TextField_Summary | TextField.Summary.cshtml |

| TextField_Summary | TextField.Summary.cshtml |

[PartType]__[FieldName]

[PartType] __ [字段名]

This template is called when a content field name is rendered for a given content part type when the shape type matches the field type, with or without a given display type.

当形状类型与字段类型匹配(具有或不具有给定显示类型)时,为给定内容部件类型呈现内容字段名称时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| HtmlBodyPart__Description | HtmlBodyPart-Description.cshtml |

| HtmlBodyPart__Description | HtmlBodyPart-Description.cshtml |

| HtmlBodyPart_Summary__Description | HtmlBodyPart-Description.Summary.cshtml |

| HtmlBodyPart_Summary__Description | HtmlBodyPart-Description.Summary.cshtml |

[ContentType]__[PartName]__[FieldName]

[ContentType的] __ [零件名称] __ [字段名]

This template is called when a content field name is rendered for a given content type and content part name when the shape type matches the field type, with or without a given display type.

当形状类型与字段类型匹配时,对于给定内容类型和内容部件名称呈现内容字段名称时,将调用此模板,具有或不具有给定的显示类型。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__HtmlBodyPart__Description | Blog-HtmlBodyPart-Description.cshtml |

| Blog__HtmlBodyPart__Description | Blog-HtmlBodyPart-Description.cshtml |

| LandingPage__Services__Image | LandingPage-Services-Image.cshtml |

| LandingPage__Services__Image | LandingPage-Services-Image.cshtml |

| Blog_Summary__HtmlBodyPart__Description | Blog-HtmlBodyPart-Description.Summary.cshtml |

| Blog_Summary__HtmlBodyPart__Description | Blog-HtmlBodyPart-Description.Summary.cshtml |

| LandingPage_Summary__Services__Image | LandingPage-Services-Image.Summary.cshtml |

| LandingPage_Summary__Services__Image | LandingPage-Services-Image.Summary.cshtml |

[ContentType]__[FieldType]

[ContentType的] __ [的FieldType]

This template is called when a content field type is rendered for a given content type when the shape type matches the field type, with or without a given display type.

当形状类型与字段类型匹配(具有或不具有给定显示类型)时,为给定内容类型呈现内容字段类型时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__TextField | Blog-TextField.cshtml |

| Blog__TextField | Blog-TextField.cshtml |

| LandingPage__TextField | LandingPage-TextField.cshtml |

| LandingPage__TextField | LandingPage-TextField.cshtml |

[FieldType]__[ShapeType]

[的FieldType] __ [ShapeType]

This template is called when a content field shape type is rendered for a given content field type, with or without a given display type.

当为给定内容字段类型呈现内容字段形状类型(具有或不具有给定显示类型)时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| CustomField__CustomFieldSummary | CustomField-CustomFieldSummary.cshtml |

| CustomField__CustomFieldSummary | CustomField-CustomFieldSummary.cshtml |

| CustomField_Summary__CustomFieldSummary | CustomField-CustomFieldSummary.Summary.cshtml |

| CustomField_Summary__CustomFieldSummary | CustomField-CustomFieldSummary.Summary.cshtml |

[PartType]__[FieldName]__[ShapeType]

[PartType] __ [字段名] __ [ShapeType]

This template is called when a content field shape type is rendered for a given content field name in a given content part type, with or without a given display type.

当为给定内容部件类型中的给定内容字段名称呈现内容字段形状类型(具有或不具有给定显示类型)时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| HtmlBodyPart__Description__CustomFieldSummary| HtmlBodyPart__Description__CustomFieldSummary.cshtml |

| HtmlBodyPart__Description__CustomFieldSummary | HtmlBodyPart__Description__CustomFieldSummary.cshtml |

| HtmlBodyPart_Summary__Description__CustomFieldSummary| HtmlBodyPart__Description__CustomFieldSummary.Summary.cshtml |

| HtmlBodyPart_Summary__Description__CustomFieldSummary | HtmlBodyPart__Description__CustomFieldSummary.Summary.cshtml |

[ContentType]__[PartName]__[FieldName]__[ShapeType]

[ContentType的] __ [零件名称] __ [字段名] __ [ShapeType]

This template is called when a content field shape type is rendered for a given content field name in a given content part name in a given content type, with or without a given display type.

当给定内容类型中给定内容部分名称中的给定内容字段名称(具有或不具有给定显示类型)呈现内容字段形状类型时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__HtmlBodyPart__Description__CustomFieldSummary | Blog-HtmlBodyPart-Description-CustomFieldSummary.cshtml |

| Blog__HtmlBodyPart__Description__CustomFieldSummary | Blog-HtmlBodyPart-Description-CustomFieldSummary.cshtml |

| LandingPage__Services__Description__CustomFieldSummary | LandingPage-Services-Description-CustomFieldSummary.cshtml |

| LandingPage__Services__Description__CustomFieldSummary | LandingPage-Services-Description-CustomFieldSummary.cshtml |

| Blog_Summary__HtmlBodyPart__Description__CustomFieldSummary | Blog-HtmlBodyPart-Description-CustomFieldSummary.Summary.cshtml |

| Blog_Summary__HtmlBodyPart__Description__CustomFieldSummary | Blog-HtmlBodyPart-Description-CustomFieldSummary.Summary.cshtml |

| LandingPage_Summary__Services__Description__CustomFieldSummary | LandingPage-Services-Description-CustomFieldSummary.Summary.cshtml |

| LandingPage_Summary__Services__Description__CustomFieldSummary | LandingPage-Services-Description-CustomFieldSummary.Summary.cshtml |

[ContentType]__[FieldType]__[ShapeType]

[ContentType的] __ [的FieldType] __ [ShapeType]

This template is called when a content field shape type is rendered for a given content field type in a given content type, with or without a given display type.

当为给定内容类型中的给定内容字段类型呈现内容字段形状类型(具有或不具有给定显示类型)时,将调用此模板。

Examples

例子

| Template | Filename|

|模板|文件名|

| --------- | ------------ |

| --------- | ------------ |

| Blog__TextField__TextFieldSummary | Blog-TextField-TextFieldSummary.cshtml |

| Blog__TextField__TextFieldSummary | Blog-TextField-TextFieldSummary.cshtml |

| LandingPage__TextField__TextFieldSummary | LandingPage-TextField-TextFieldSummary.cshtml |

| LandingPage__TextField__TextFieldSummary | LandingPage-TextField-TextFieldSummary.cshtml |

Shape differentiators

形状差异化

The differentiator uniquely identifies a shape in a zone. When rendering a content item, the shape has a Content property that contains

微分器唯一地标识区域中的形状。渲染内容项时,形状具有包含的“Content”属性

all the shapes provided by content display drivers, including the ones for content parts and content fields.

内容显示驱动程序提供的所有形状,包括内容部分和内容字段的形状。

Differentiators can be used to configure the placement information (c.f. Placement documentation page), or to access specific shapes in a zone using these template helpers:

微分器可用于配置放置信息(c.f。[放置文档页面](../../ OrchardCore / OrchardCore.DisplayManagement / README)),或使用这些模板助手访问区域中的特定形状:

Content Part differentiator

内容部分差异化

If the shape type is the same as the content part name, the shape will be named [PartName], e.g. HtmlBodyPart, Services.

如果形状类型与内容部分名称相同,则形状将命名为“[PartName]”,例如HtmlBodyPartServices

If the shape type is different than the content part name, it will be [PartName]-[ShapeType], e.g. ListPart-ListPartFeed

如果形状类型与内容部分名称不同,则它将是“[PartName] - [ShapeType]”,例如ListPart-ListPartFeed

Content Field differentiator

内容领域差异化

If the shape type is the same as the content field name, the shape will be named [PartName]-[FieldName], e.g. HtmlBodyPart-Description, Services-Image.

如果形状类型与内容字段名称相同,则形状将命名为“[PartName] - [FieldName],例如,HtmlBodyPart-DescriptionServices-Image`。

If the shape type is different than the content field name, it will be [PartName]-[FieldName]-[ShapeType], e.g. HtmlBodyPart-Description-CustomFieldSummary, Services-Image-ImageFieldSummary

如果形状类型与内容字段名称不同,则它将是“[PartName] - [FieldName] - [ShapeType]”,例如HtmlBodyPart-Description-CustomFieldSummaryServices-Image-ImageFieldSummary

Razor

剃刀

Access a specific shape by name

按名称访问特定形状


Model.Content.HtmlBodyPart

 <font color=#0099ff size=4 face="黑体">Model.Content.HtmlBodyPart</font> 


Removing a specific shape by name

按名称删除特定形状


Model.Content.Remove("HtmlBodyPart");

 <font color=#0099ff size=4 face="黑体">Model.Content.Remove( “HtmlBodyPart”);</font> 


Liquid

液体

Display a shape after removing a specific shape by name

按名称删除特定形状后显示形状


{% shape_remove_item Model.Content "HtmlBodyPart" %}

 <font color=#0099ff size=4 face="黑体">{%shape_remove_item Model.Content“HtmlBodyPart”%}</font> 


{{ Model.Content | shape_render }}

 <font color=#0099ff size=4 face="黑体">{{Model.Content | shape_render}}</font> 


Display a specific shape by name

按名称显示特定形状


{{ Model.Content.HtmlBodyPart | shape_render }}

 <font color=#0099ff size=4 face="黑体">{{Model.Content.HtmlBodyPart | shape_render}}</font> 


To access or render the shapes for a field that is added to the content type directly, the [PartName] is equal to the content type.

要访问或呈现直接添加到内容类型的字段的形状,[PartName]等于内容类型。

For instance, given a content type Article with a Text field named Description, the shapes for this field would be named "Article-Description". Render these shapes in Liquid would be:

例如,给定一个带有名为Description的Text字段的内容类型Article,该字段的形状将被命名为“Article-Description”。在Liquid中渲染这些形状将是:


{{ Model.Content["Article-Description"] | shape_render }}

 <font color=#0099ff size=4 face="黑体">{{Model.Content [“Article-Description”] | shape_render}}</font> 


In this example the indexer syntax is necessary as the name of the differentiator is not compatible with Liquid language.

在此示例中,索引器语法是必需的,因为微分器的名称与Liquid语言不兼容。

Instead of rendering the shape directly, you can also access its properties. In the case of a text field you have access to the Field property which has a Text property.

您也可以访问其属性,而不是直接渲染形状。在文本字段的情况下,您可以访问具有“Text”属性的Field属性。


{{ Model.Content["Article-Description"].Field.Text }}

 <font color=#0099ff size=4 face="黑体">{{Model.Content [“Article-Description”]。Field.Text}}</font>