Liquid (OrchardCore.Liquid)
液体(OrchardCore.Liquid)
This module provides a way to create templates securely from the admin site.
此模块提供了一种从管理站点安全地创建模板的方法。
For more information about the Liquid syntax, please refer to this site: https://shopify.github.io/liquid/
有关Liquid语法的更多信息,请参阅此站点:https://shopify.github.io/liquid/
General concepts
一般概念
HTML escaping
HTML转义
All outputs are encoded into HTML by default.
默认情况下,所有输出都编码为HTML。
This means that any HTML reserved chars will be converted to the corresponding HTML entities.
这意味着任何HTML保留的字符都将转换为相应的HTML实体。
If you need to render some raw HTML chars you can use the Raw
filter.
如果需要渲染一些原始HTML字符,可以使用Raw
过滤器。
Content Item Filters
内容项过滤器
All the default filters that are available in the standard Liquid syntax are available in OrchardCore.
OrchardCore中提供了标准Liquid语法中可用的所有默认过滤器。
On top of that each Orchard module can provide custom filters for their own purpose.
最重要的是,每个Orchard模块都可以为自己的目的提供自定义过滤器。
Here is a list of common filters that apply to content items.
以下是适用于内容项的常用过滤器列表。
display_url
DISPLAY_URL
Returns the URL of the content item
返回内容项的URL
Input
输入
{{ Model.ContentItem | display_url }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem | display_url}}</font>
Output
产量
/blog/my-blog-post
<font color=#0099ff size=4 face="黑体">/博客/我 - 博客 - 岗位</font>
display_text
DISPLAY_TEXT
Returns the title of the content item
返回内容项的标题
Input
输入
{{ Model.ContentItem | display_text }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem | display_text}}</font>
Output
产量
My Blog Post
<font color=#0099ff size=4 face="黑体">我的博文</font>
slugify
slugify
Convert a text into a string that can be used in a URL.
将文本转换为可在URL中使用的字符串。
Input
输入
{{ "This is some text" | slugify }}
<font color=#0099ff size=4 face="黑体">{{“这是一些文字”| slugify}}</font>
Output
产量
this-is-some-text
<font color=#0099ff size=4 face="黑体">这 - 是 - 一些文本</font>
container
容器
Returns the container content item of another content item.
返回另一个内容项的容器内容项。
Input
输入
{{ Model.ContentItem | container | display_text }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem |容器| display_text}}</font>
In this example we assume ContentItem
represents a blog post.
在这个例子中,我们假设ContentItem
代表博客文章。
Output
产量
Blog
<font color=#0099ff size=4 face="黑体">博客</font>
local
本地
Converts a UTC date and time to the local date and time based on the site settings.
根据站点设置将UTC日期和时间转换为本地日期和时间。
Input
输入
{{ "now" | local | date: "%c" }}
<font color=#0099ff size=4 face="黑体">{{“now”|当地的|日期:“%c”}}</font>
or
要么
{{ Model.ContentItem.CreatedUtc | local | date: "%c" }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem.CreatedUtc |当地的|日期:“%c”}}</font>
Output
产量
Wednesday, 02 August 2017 11:54:48
<font color=#0099ff size=4 face="黑体">2017年8月2日星期三11:54:48</font>
t
Ť
Localizes a string using the current culture.
使用当前文化本地化字符串。
Input
输入
{{ "Hello!" | t }}
<font color=#0099ff size=4 face="黑体">{{ “你好!” | t}}</font>
Output
产量
Bonjour!
<font color=#0099ff size=4 face="黑体">你好!</font>
html_class
html_class
Converts a string into a friendly HTML class.
将字符串转换为友好的HTML类。
Input
输入
{{ "LandingPage" | html_class }}
<font color=#0099ff size=4 face="黑体">{{“LandingPage”| html_class}}</font>
Output
产量
landing-page
<font color=#0099ff size=4 face="黑体">登陆页面</font>
Markdownify
Markdownify
Converts a Markdown string to HTML.
将Markdown字符串转换为HTML。
Input
输入
{{ "### Services" | markdownify }}
<font color=#0099ff size=4 face="黑体">{{“###服务”|降价}}</font>
Output
产量
<h3>Services</h3>
<font color=#0099ff size=4 face="黑体"><H3>服务</ H3></font>
Properties
属性
By default the liquid templates have access to a common set of objects.
默认情况下,液体模板可以访问一组公共对象。
Model.Content
Model.Content
When available, a zone shape that contains all the shapes generated by the content's parts and fields.
可用时,区域形状包含内容的部件和字段生成的所有形状。
Model.ContentItem
Model.ContentItem
When available, represents the current content item being rendered.
可用时,表示正在呈现的当前内容项。
The following properties are available on the ContentItem
object.
ContentItem
对象提供以下属性。
| Property | Example | Description |
|财产|示例|说明|
| --------- | ---- |------------ |
| --------- | ---- | ------------ |
| Id
| 12
| The id of the document in the database |
| Id
| 12
|数据库中文档的ID |
| ContentItemId
| 4qs7mv9xc4ttg5ktm61qj9dy5d
| The common identifier of all versions of the content item |
| ContentItemId
| 4qs7mv9xc4ttg5ktm61qj9dy5d
|内容项的所有版本的公共标识符
| ContentItemVersionId
| 4jp895achc3hj1qy7xq8f10nmv
| The unique identifier of the content item version |
| ContentItemVersionId
| 4jp895achc3hj1qy7xq8f10nmv
|内容项版本的唯一标识符
| Number
| 6
| The version number |
| Number
| 6
|版本号|
| Owner
| admin
| The username of the creator of this content item |
| '所有者'| admin
|此内容项的创建者的用户名
| Author
| admin
| The username of the editor of this version |
| 作者
| admin
|此版本的编辑器的用户名|
| Published
| true
| Whether this content item version is published or not |
| 已发布
| true
|是否发布此内容项版本|
| Latest
| true
| Whether this content item version is the latest of the content item |
| Latest
| true
|此内容项版本是否是最新的内容项|
| ContentType
| BlogPost
| The content type |
| ContentType
| BlogPost
|内容类型|
| CreatedUtc
| 2017-05-25 00:27:22.647
| When the content item was first created or first published |
| CreatedUtc
| 2017-05-25 00:27:22.647
|首次创建或首次发布内容项时
| ModifiedUtc
| 2017-05-25 00:27:22.647
| When the content item version was created |
| ModifiedUtc
| 2017-05-25 00:27:22.647
|创建内容项版本时|
| PublishedUtc
| 2017-05-25 00:27:22.647
| When the content item was last published |
| PublishedUtc
| 2017-05-25 00:27:22.647
|上次发布内容项时|
| Content
| { ... }
| A document containing all the content properties. See specific documentation for usage .|
| 内容
| {...}
|包含所有内容属性的文档。有关用法,请参阅特定文档
Content property
内容属性
The Content
property of a content item exposes all its elements, like parts and fields. It is possible to
内容项的“Content”属性公开其所有元素,如部分和字段。有可能
inspect all the available properties by evaluating Content
directly. It will then render the full document.
通过直接评估Content
来检查所有可用的属性。然后它将呈现完整的文档。
The convention is that each Part is exposed by its name as the first level.
惯例是每个Part都以其名称作为第一级公开。
If the content item has custom fields, they will be available under a part whose name will match the content type.
如果内容项具有自定义字段,则它们将在名称与内容类型匹配的部件下可用。
For example, assuming the type Product
has a Text field named Size
, access the value of this field for a
例如,假设类型Product
有一个名为Size
的文本字段,请访问该字段的值
content item as follows:
内容项目如下:
{{ Model.ContentItem.Content.Product.Size.Text }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem.Content.Product.Size.Text}}</font>
Similarly, if the content item has a Title
part, we can access it like this:
类似地,如果内容项具有“标题”部分,我们可以像这样访问它:
{{ Model.ContentItem.Content.TitlePart.Title }}
<font color=#0099ff size=4 face="黑体">{{Model.ContentItem.Content.TitlePart.Title}}</font>
User
用户
Represents the authenticated user for the current request.
表示当前请求的经过身份验证的用户。
The following properties are available on the User
object.
“User”对象上提供了以下属性。
| Property | Example | Description |
|财产|示例|说明|
| --------- | ---- |------------ |
| --------- | ---- | ------------ |
| Identity.Name
| admin
| The name of the authenticated user |
| Identity.Name
| admin
|经过身份验证的用户的名称
Site
现场
Gives access to the current site settings, e.g Site.SiteName
.
提供对当前站点设置的访问,例如“Site.SiteName”。
| Property | Example | Description |
|财产|示例|说明|
| -------- | ------- |------------ |
| -------- | ------- | ------------ |
| BaseUrl
| | The base URL of the site |
| BaseUrl
| |站点的基本URL |
| Calendar
| | The site's calendar |
| 日历
| |该网站的日历|
| Culture
| en-us
| The site's default culture as an ISO language code |
| 文化
| en-us
|该网站的默认文化为ISO语言代码|
| MaxPagedCount
| 0
| The maximum number of pages that can be paged |
| MaxPagedCount
| 0
|可以分页的最大页数
| MaxPageSize
| 100
| The maximum page size that can be set by a user |
| MaxPageSize
| 100
|用户可以设置的最大页面大小
| PageSize
| 10
| The default page size of lists |
| PageSize
| 10
|列表的默认页面大小|
| SiteName
| My Site
| The friendly name of the site |
| SiteName
| 我的网站
|网站的友好名称|
| SuperUser
| admin
| The user name of the site's super user |
| 超级用户
| admin
|站点的超级用户的用户名|
| TimeZoneId
| America/Los_Angeles
| The site's time zone id as per the tz database, c.f., https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
| TimeZoneId
| America / Los_Angeles
|该网站的时区ID根据tz数据库,c.f。,https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
| UseCdn
| false
| Enable/disable the use of a CDN |
| UseCdn
| false
|启用/禁用CDN的使用
Request
请求
Represents the current request.
表示当前请求。
The following properties are available on the Request
object.
“Request”对象上提供了以下属性。
| Property | Example | Description |
|财产|示例|说明|
| --------- | ---- |------------ |
| --------- | ---- | ------------ |
| QueryString
| ?sort=name&page=1
| The query string |
| QueryString
| ?sort = name&page = 1
|查询字符串|
| ContentType
| application/x-www-form-urlencoded; charset=UTF-8
| The Content-Type
header |
| ContentType
| 应用程序/ x-WWW窗体-urlencoded; charset = UTF-8
| Content-Type
标题|
| ContentLength
| 600
| The Content-Length
header |
| ContentLength
| 600
| Content-Length
标题|
| Cookies
| Usage: Request.Cookies.orchauth_Default
| The collection of cookies for this request |
| Cookies
|用法:Request.Cookies.orchauth_Default
|此请求的cookie集合|
| Headers
| Usage: Request.Headers.accept
| The request headers |
| 标题
|用法:Request.Headers.accept
|请求标头|
| Query
| Usage: Request.Query.sort
| The query value collection parsed from QueryString
|
| 查询
|用法:Request.Query.sort
|查询值集合从QueryString
|解析
| Form
| Usage: Request.Form.value
| The collection of form values |
| Form
|用法:Request.Form.value
|表单值的集合|
| Protocol
| https
| The protocol of this request |
| Protocol
| https
|此请求的协议|
| Path
| /OrchardCore.ContentPreview/Preview/Render
| The path of the request, unescaped |
| Path
| / OrchardCore.ContentPreview / Preview / Render
|请求的路径,未转义|
| PathBase
| /mytenant
| The base path of the request, unescaped |
| PathBase
| / mytenant
|请求的基本路径,未转义|
| Host
| localhost:44300
| The Host
header. May contain the port |
| 主持人|
localhost:44300|
Host`标题。可能包含端口|
| IsHttps
| true
| True if the scheme of the request is https
|
| IsHttps
| true
|如果请求的方案是“https”|,则为True
| Scheme
| https
| The scheme of the request |
| Scheme
| https
|请求的方案|
| Method
| GET
| The HTTP method |
| 方法
| GET
| HTTP方法|
Culture
文化
Represents the current culture.
代表当前的文化。
The following properties are available on the Culture
object.
Culture
对象提供以下属性。
| Property | Example | Description |
|财产|示例|说明|
| --------- | ---- |------------ |
| --------- | ---- | ------------ |
| Name
| en-US
| The requests's culture as an ISO language code |
| 姓名
| en-US
|请求的文化作为ISO语言代码|
| Dir
| rtl
| The text writing directionality |
| Dir
| rtl
|文字写作方向性|
Shape Filters
形状滤镜
These filters let you create and filter shapes.
使用这些过滤器可以创建和过滤形状。
shape_new
shape_new
Returns a shape with the specified name as input.
返回具有指定名称作为输入的形状。
Input
输入
{% assign date_time = "DateTime" | shape_new %}
<font color=#0099ff size=4 face="黑体">{%assign date_time =“DateTime”| shape_new%}</font>
shape_render
shape_render
Renders a shape.
渲染形状。
Input
输入
{{ Model.Content | shape_render }}
<font color=#0099ff size=4 face="黑体">{{Model.Content | shape_render}}</font>
<font color=#0099ff size=4 face="黑体"></font>
shape_stringify
shape_stringify
Converts a shape to its string representation. Contrary to shape_render
the result of this filter will
将形状转换为其字符串表示形式。与shape_render
相反,此过滤器的结果将是
be encoded if rendered in the output.
如果在输出中呈现,则进行编码。
Input
输入
{{ "DateTime" | shape_new | shape_stringify }}
<font color=#0099ff size=4 face="黑体">{{“DateTime”| shape_new | shape_stringify}}</font>
<font color=#0099ff size=4 face="黑体"></font>
Output
产量
Monday, September 11, 2017 3:29:26 PM
<font color=#0099ff size=4 face="黑体">2017年9月11日星期一下午3:29:26</font>
Layout Tags
布局标签
layout
布局
Sets the layout of a view.
设置视图的布局。
Input
输入
{% layout "CustomLayout" %}
<font color=#0099ff size=4 face="黑体">{%layout“CustomLayout”%}</font>
Internally an alternate is added to the current theme Layout
shape.
在内部,替代品被添加到当前主题“布局”形状中。
render_body
render_body
In a layout, renders the body of the current view.
在布局中,呈现当前视图的主体。
Input
输入
{% render_body %}
<font color=#0099ff size=4 face="黑体">{%render_body%}</font>
render_section
render_section
In a layout, renders the section with the specified name.
在布局中,使用指定的名称呈现节。
Input
输入
{% render_section "Header", required: false %}
<font color=#0099ff size=4 face="黑体">{%render_section“标题”,必填:false%}</font>
page_title
页面标题
Alters and renders the title of the current page.
更改并呈现当前页面的标题。
Input
输入
{% page_title Site.SiteName, position: "before", separator: " - " %}
<font color=#0099ff size=4 face="黑体">{%page_title Site.SiteName,position:“before”,separator:“ - ”%}</font>
The default parameter is a text that is appended to the current value of the title.
默认参数是附加到标题当前值的文本。
position
is where the value is appended, in this example at the beginning.
separator
is a string that is used to separate all the fragments of the title.
Shape Tags
形状标签
shape_clear_alternates
shape_clear_alternates
Removes any alternates from a shape.
从形状中删除任何替换。
Input
输入
{% shape_clear_alternates my_shape %}
<font color=#0099ff size=4 face="黑体">{%shape_clear_alternates my_shape%}</font>
<font color=#0099ff size=4 face="黑体"></font>
shape_add_alternates
shape_add_alternates
Adds alternates to a shape.
添加替代形状。
Input
输入
{% shape_add_alternates my_shape "alternate1", "alternate2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_alternates my_shape“alternate1”,“alternate2”%}</font>
{% shape_add_alternates my_shape "alternate1 alternate2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_alternates my_shape“alternate1 alternate2”%}</font>
shape_clear_wrappers
shape_clear_wrappers
Removes any wrappers from a shape.
从形状中移除任何包装。
Input
输入
{% shape_clear_wrappers my_shape %}
<font color=#0099ff size=4 face="黑体">{%shape_clear_wrappers my_shape%}</font>
<font color=#0099ff size=4 face="黑体"></font>
shape_add_wrappers
shape_add_wrappers
Adds wrappers to a shape.
将包装器添加到形状。
Input
输入
{% shape_add_wrappers my_shape "wrapper1", "wrapper2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_wrappers my_shape“wrapper1”,“wrapper2”%}</font>
{% shape_add_wrappers my_shape "wrapper1 wrapper2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_wrappers my_shape“wrapper1 wrapper2”%}</font>
shape_clear_classes
shape_clear_classes
Removes any classes from a shape.
从形状中删除任何类。
Input
输入
{% shape_clear_classes my_shape %}
<font color=#0099ff size=4 face="黑体">{%shape_clear_classes my_shape%}</font>
shape_add_classes
shape_add_classes
Adds classes to a shape.
将类添加到形状。
Input
输入
{% shape_add_classes my_shape "class1 class2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_classes my_shape“class1 class2”%}</font>
{% shape_add_classes my_shape "class1", "class2" %}
<font color=#0099ff size=4 face="黑体">{%shape_add_classes my_shape“class1”,“class2”%}</font>
shape_clear_attributes
shape_clear_attributes
Removes any attributes from a shape.
从形状中删除任何属性。
Input
输入
{% shape_clear_attributes my_shape %}
<font color=#0099ff size=4 face="黑体">{%shape_clear_attributes my_shape%}</font>
shape_add_attributes
shape_add_attributes
Adds attributes to a shape.
将属性添加到形状。
Input
输入
{% shape_add_attributes my_shape attr_name1: "value1", attr_name2: "value2" ... %}
<font color=#0099ff size=4 face="黑体">{%shape_add_attributes my_shape attr_name1:“value1”,attr_name2:“value2”...%}</font>
shape_type
SHAPE_TYPE
Sets the type of a shape.
设置形状的类型。
Input
输入
{% shape_type my_shape "MyType" %}
<font color=#0099ff size=4 face="黑体">{%shape_type my_shape“MyType”%}</font>
Whenever the type is changed, it is recommended to clear the shape alternates before using the shape_clear_alternates
tag.
每当更改类型时,建议在使用shape_clear_alternates
标记之前交替清除形状。
shape_display_type
shape_display_type
Sets the display type of a shape.
设置形状的显示类型。
Input
输入
{% shape_display_type my_shape "Summary" %}
<font color=#0099ff size=4 face="黑体">{%shape_display_type my_shape“摘要”%}</font>
Whenever the display type is changed, it is recommended to clear the shape alternates before.
每当更改显示类型时,建议先交替清除形状。
shape_position
shape_position
Sets the position of a shape.
设置形状的位置。
Input
输入
{% shape_position my_shape "Content:before" %}
<font color=#0099ff size=4 face="黑体">{%shape_position my_shape“内容:在”%}之前</font>
<font color=#0099ff size=4 face="黑体"></font>
shape_tab
shape_tab
Sets the tab of a shape.
设置形状的选项卡。
Input
输入
{% shape_tab my_shape "properties" %}
<font color=#0099ff size=4 face="黑体">{%shape_tab my_shape“properties”%}</font>
<font color=#0099ff size=4 face="黑体"></font>
shape_remove_item
shape_remove_item
Removes a shape by its name in a Zone.
在区域中删除其名称的形状。
Input
输入
{% 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>
In this example, the Model.Content
property evaluates to a zone shape, typically from a Content Item shape template, which contains the HtmlBodyPart
shape
在此示例中,Model.Content
属性计算为区域形状,通常来自Content Item形状模板,其中包含HtmlBodyPart
形状
rendered for the Body Part element. This call will remove the specific shape named HtmlBodyPart
.
为Body Part元素渲染。此调用将删除名为“HtmlBodyPart”的特定形状。
shape_pager
shape_pager
Replaces the properties of a Pager shape.
替换寻呼机形状的属性。
Input
输入
{% shape_pager Model.Pager next_class: 'next', next_text: '>>' %}
<font color=#0099ff size=4 face="黑体">{%shape_pager Model.Pager next_class:'next',next_text:'>>'%}</font>
shape_build_display
shape_build_display
Creates the display shape for a content item. It can be used in conjunction with shape_render
创建内容项的显示形状。它可以与shape_render
一起使用
to render a content item.
呈现内容项。
Input
输入
{{ mycontentitem | shape_build_display: "Detail" | shape_render }}
<font color=#0099ff size=4 face="黑体">{{mycontentitem | shape_build_display:“细节”| shape_render}}</font>
shape
形状
Renders a specific named tag with its properties
使用其属性呈现特定的命名标记
Input
输入
{% shape "menu", alias: "alias:main-menu", cache_id: "main-menu", cache_expires_after: "00:05:00", cache_tag: "alias:main-menu" %}
<font color=#0099ff size=4 face="黑体">{%shape“menu”,别名:“alias:main-menu”,cache_id:“main-menu”,cache_expires_after:“00:05:00”,cache_tag:“alias:main-menu”%}</font>
When using the shape tag a specific wrapper and / or alternate can be specified.
使用形状标记时,可以指定特定的包装和/或替换。
{% shape "menu", alias: "alias:main-menu", alternate: "Menu_Footer" %}
<font color=#0099ff size=4 face="黑体">{%shape“menu”,别名:“alias:main-menu”,alternate:“Menu_Footer”%}</font>
zone
区
Renders some HTML content in the specified zone.
在指定区域中呈现一些HTML内容。
Input
输入
{% zone "Header" %}
<font color=#0099ff size=4 face="黑体">{%zone“标题”%}</font>
<!-- some content goes here -->
{% endzone %}
<font color=#0099ff size=4 face="黑体">{%endzone%}</font>
The content of this block can then be reused from the Layout using the {{ Model.Header | shape_render }}
code.
然后可以使用{{Model.Header |。 - 从布局重用该块的内容shape_render}}
代码。
Tag Helper tags
Tag Helper标签
ASP.NET Core MVC provides a set of tag helpers to render predefined HTML outputs. The Liquid module provides a way to call into these Tag Helpers using custom liquid tags.
ASP.NET Core MVC提供了一组标记帮助器来呈现预定义的HTML输出。 Liquid模块提供了一种使用自定义液体标签调用这些Tag Helpers的方法。
link
链接
Invokes the link
tag helper from the Orchard.ResourceManagement package.
从 Orchard.ResourceManagement 包调用link
标签助手。
meta
元
Invokes the meta
tag helper from the Orchard.ResourceManagement package.
从 Orchard.ResourceManagement 包调用meta
标签帮助器。
resources
资源
Invokes the resources
tag helper from the Orchard.ResourceManagement package.
从 Orchard.ResourceManagement 包中调用resources
标签帮助器。
script
脚本
Invokes the script
tag helper from the Orchard.ResourceManagement package.
从 Orchard.ResourceManagement 包调用script
标签帮助器。
style
样式
Invokes the style
tag helper from the Orchard.ResourceManagement package.
从 Orchard.ResourceManagement 包中调用style
标签助手。
a
一个
Invokes the a
content link tag helper from the OrchardCore.Contents package.
从 OrchardCore.Contents 包中调用a
内容链接标记助手。
antiforgerytoken
antiforgerytoken
Renders a <hidden>
element (antiforgery token) that will be validated when the containing <form>
is submitted.
呈现一个<hidden>
元素(防伪标记),当提交包含“
Example
例
{% antiforgerytoken %}
<font color=#0099ff size=4 face="黑体">{%antiforgerytoken%}</font>
CREDITS
学分
Fluid
流体
https://github.com/sebastienros/fluid
https://github.com/sebastienros/fluid
Copyright (c) 2017 Sebastien Ros
版权所有(c)2017 Sebastien Ros
MIT License
MIT许可证