Skip to content

Content Fields (OrchardCore.ContentFields)

内容字段(OrchardCore.ContentFields)

Purpose

目的

This modules provides common content fields.

此模块提供公共内容字段。

Available Fields

可用字段

| Name | Properties | Shape Type | Shape Class |

|名称|属性|形状类型|形状类|

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

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

| BooleanField | Value (bool) | BooleanField | DisplayBooleanFieldViewModel |

| BooleanField | 价值(布尔)| BooleanField | DisplayBooleanFieldViewModel |

| DateField | Value (DateTime?) | DateField | DisplayDateFieldViewModel |

| DateField | Value(DateTime?)| DateField | DisplayDateFieldViewModel |

| DateTimeField | Value (DateTime?) | DateTimeField | DisplayDateTimeFieldViewModel |

| DateTimeField | Value(DateTime?)| DateTimeField | DisplayDateTimeFieldViewModel |

| HtmlField | Html (string) | HtmlField | DisplayHtmlFieldViewModel |

| HtmlField | Html(string)| HtmlField | DisplayHtmlFieldViewModel |

| LinkField | Url (string), Text (string) | LinkField | DisplayLinkFieldViewModel |

| LinkField | url(string),Text(string)| LinkField | DisplayLinkFieldViewModel |

| NumericField | Value (decimal?) | NumericField | DisplayNumericFieldViewModel |

| NumericField | 值(十进制?)| NumericField | DisplayNumericFieldViewModel |

| TextField | Text (string) | TextField | DisplayTextFieldViewModel |

| TextField | Text(string)| TextField | DisplayTextFieldViewModel |

| TimeField | Value (TimeSpan?) | TimeField | DisplayTimeFieldViewModel |

| TimeField | 值(TimeSpan?)| TimeField | DisplayTimeFieldViewModel |

Usage

用法

From a Content template, you can reference a field's value like this

从“Content”模板中,您可以像这样引用字段的值

(if the content type is Article and has a Text Field named MyField):

(如果内容类型是“Article”并且有一个名为“MyField”的文本字段):


var fieldValue = Model.ContentItem.Content.Article.MyField.Text;

 <font color=#0099ff size=4 face="黑体">var fieldValue = Model.ContentItem.Content.Article.MyField.Text;</font> 



{{ Model.ContentItem.Content.Article.MyField.Value }}

 <font color=#0099ff size=4 face="黑体">{{Model.ContentItem.Content.Article.MyField.Value}}</font> 


From a field shape (see Shape Type in the table listing all the fields) you can also access properties specific to each view model.

从字段形状(请参阅列出所有字段的表中的形状类型),您还可以访问特定于每个视图模型的属性。

Common field properties

常用字段属性

The convention for a field view model is to also expose these properties:

字段视图模型的约定是也公开这些属性:

| Property | Description |

|财产|说明|

| --- | --- |

| --- | --- |

| Field | The ContentField. |

| Field | ContentField。 |

| Part | The ContentPart that contains the field. |

| Part |包含该字段的ContentPart。 |

| ContentPartFieldDefinition | The Content Part Field Definition that contains the part. Which also give access to the Content Type |

| ContentPartFieldDefinition |包含部件的内容部件字段定义。这也提供了对内容类型的访问权限

Some view models have special properties that are computed from the actual field data and which are more useful for templating.

某些视图模型具有根据实际字段数据计算的特殊属性,这些属性对模板更有用。

DisplayHtmlFieldViewModel

DisplayHtmlFieldViewModel

| Property | Description |

|财产|说明|

| --- | --- |

| --- | --- |

| Html | The processed Html once all liquid tags are processed. |

| Html |处理完所有液体标签后处理过的Html。 |

HtmlField Example

HtmlField示例


{{ Model.Html }}

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


or, to display the raw content before the tags are converted:

或者,在转换标签之前显示原始内容:


{{ Model.Field.Html }}

 <font color=#0099ff size=4 face="黑体">{{Model.Field.Html}}</font> 


DisplayDateTimeFieldViewModel

DisplayDateTimeFieldViewModel

| Property | Description |

|财产|说明|

| --- | --- |

| --- | --- |

| LocalDateTime | The date time in the time zone of the site. |

| LocalDateTime |站点时区中的日期时间。 |

DateTimeField Example

DateTimeField示例


{{ Model.LocalDateTime }}

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


or, to display the UTC value before is it converted:

或者,在转换之前显示UTC值:


{{ Model.Field.Value }}

 <font color=#0099ff size=4 face="黑体">{{Model.Field.Value}}</font> 


Creating Custom Fields

创建自定义字段

What to extend

什么延伸

Before creating a new field the solution might be to provide a custom editor and formatter

在创建新字段之前,解决方案可能是提供自定义编辑器和格式化程序

instead.

代替。

A field should represent some specific physical data and logical data. The same field can be customized

字段应表示某些特定的物理数据和逻辑数据。可以自定义相同的字段

to be edited and rendered differently using both Editors and Formatters. Editors are shapes that can

使用编辑器和格式化程序进行不同的编辑和渲染。编辑是可以的形状

be used to edit a field differently, for instance the WYSIWYG HTML editor is a custom editor for the HTML

用于以不同方式编辑字段,例如WYSIWYG HTML编辑器是HTML的自定义编辑器

field. Formatters are alternate shapes that can be used to render a field on the front end, for instance

领域。例如,格式化程序是可用于在前端渲染字段的替代形状

a Link field could be rendered as a Youtube video player.

链接字段可以呈现为Youtube视频播放器。

Model Class

模型类

Create a class inheriting from ContentField that will represent the state of your field.

创建一个继承自“ContentField”的类,它将表示字段的状态。

Its content will be serialized as part of the content item.

其内容将作为内容项的一部分进行序列化。

Json.NET classes can be used to customize the serialization.

Json.NET类可用于自定义序列化。

Example:

例:


public class TextField : ContentField

 <font color=#0099ff size=4 face="黑体">公共类TextField:ContentField</font> 


{

 <font color=#0099ff size=4 face="黑体">{</font> 


    public string Text { get; set; }

}

 <font color=#0099ff size=4 face="黑体">}</font> 





 <font color=#0099ff size=4 face="黑体"></font> 


This class needs to be registered in the DI like this:

这个类需要在DI中注册,如下所示:


services.AddSingleton<ContentField, TextField>();

 <font color=#0099ff size=4 face="黑体">services.AddSingleton <ContentField,TextField>();</font> 


Display Driver

显示驱动程序

The display driver is the component that drives how the field is displayed on the front end, edited on

显示驱动程序是驱动字段在前端显示的方式的组件,在其上进行编辑

the admin, updated and validated.

管理员,更新和验证。

Create a class inheriting from ContentFieldDisplayDriver<TextField> and implement the three methods

创建一个继承自ContentFieldDisplayDriver <TextField>的类,并实现这三个方法

Display, Edit and DisplayAsync by looking at examples from this module.

This class needs to be registered in the DI like this:

这个类需要在DI中注册,如下所示:


services.AddScoped<IContentFieldDisplayDriver, TextFieldDisplayDriver>();

 <font color=#0099ff size=4 face="黑体">services.AddScoped <IContentFieldDisplayDriver,TextFieldDisplayDriver>();</font> 


Creating Custom Editors

创建自定义编辑器

For each field, the convention is to create an alternate that can target different editors. To provide

对于每个字段,约定是创建可以针对不同编辑器的替代。提供

a new choice in the list of available editors for a field, create a new shape template that matches this

在字段的可用编辑器列表中的新选项,创建与此匹配的新形状模板

template: {FIELDTYPE}_Option__{EDITORNAME}

模板:{FIELDTYPE} _Option __ {EDITORNAME}

This shape type will match a template file named {FIELDTYPE}-{EDITORNAME}.Option.cshtml

此形状类型将匹配名为{FIELDTYPE} - {EDITORNAME} .Option.cshtml的模板文件

This template will need to render an <option> tag. Here is an example for a Wysiwyg options on the Html Field:

该模板需要呈现一个<option>标签。以下是Html字段上Wysiwyg选项的示例:


@{

 <font color=#0099ff size=4 face="黑体">@ {</font> 


    string currentEditor = Model.Editor;

}

 <font color=#0099ff size=4 face="黑体">}</font> 


<option value="Wysiwyg" selected="@(currentEditor == "Wysiwyg")">@T["Wysiwyg editor"]</option>

 <font color=#0099ff size=4 face="黑体"><option value =“Wysiwyg”selected =“@(currentEditor ==”Wysiwyg“)”> @ T [“Wysiwyg编辑”] </ option></font> 


Then you can create the editor shape by adding a file named {FIELDTYPE}_Editor__{EDITORNAME} which is

然后你可以通过添加一个名为{FIELDTYPE} _Editor __ {EDITORNAME}的文件来创建编辑器形状。

represented by a template file named {FIELDTYPE}-{EDITORNAME}.Editor.cshtml.

由名为{FIELDTYPE} - {EDITORNAME} .Editor.cshtml的模板文件表示。

For instance the filename for the Wysiwyg editor on the Html Field is named HtmlField-Wysiwyg.Editor.cshtml.

例如,Html字段上Wysiwyg编辑器的文件名为“HtmlField-Wysiwyg.Editor.cshtml”。

CREDITS

学分

bootstrap-slider

引导滑块

https://github.com/seiyria/bootstrap-slider

https://github.com/seiyria/bootstrap-slider

Copyright (c) 2017 Kyle Kemp, Rohit Kalkur, and contributors

版权所有(c)2017 Kyle Kemp,Rohit Kalkur和贡献者

License: MIT

执照:麻省理工学院

Bootstrap Switch

自举开关

https://github.com/Bttstrp/bootstrap-switch

https://github.com/Bttstrp/bootstrap-switch

Copyright (c) 2013-2015 The authors of Bootstrap Switch

版权所有(c)2013-2015 Bootstrap Switch的作者

License: MIT

执照:麻省理工学院