Skip to content

Contents (OrchardCore.Contents)

内容(OrchardCore.Contents)

This module provides Content Management services.

此模块提供内容管理服务。

Liquid

液体

You can access content items from liquid views and templates by using the Content property.

您可以使用“Content”属性从液体视图和模板访问内容项。

By default, you can retrieve content by alias or content item ID. Other modules (such as Alias and Autoroute) allow you to retrieve content by other identifiers.

默认情况下,您可以按别名或内容项ID检索内容。其他模块(如Alias和Autoroute)允许您通过其他标识符检索内容。

Loading from an alias

从别名加载


{% assign my_content = Content["alias:main-menu"] %}

 <font color=#0099ff size=4 face="黑体">{%assign my_content = Content [“alias:main-menu”]%}</font> 


Aliases can be in various forms, like when using Autoroute, with the slug prefix.

别名可以采用各种形式,例如使用Autoroute时使用slug前缀。


{% assign my_content = Content["slug:my-blog/my-blog-post"] %}

 <font color=#0099ff size=4 face="黑体">{%assign my_content = Content [“slug:my-blog / my-blog-post”]%}</font> 


Aliases are provided by implementing IContentAliasProvider.

通过实现IContentAliasProvider提供别名。

Loading the latest version of a content item

加载内容项的最新版本

You can use the Latest property to retrieve the latest version of a content item (whether that's the published version or the latest draft version) by alias:

您可以使用“Latest”属性通过别名检索内容项的最新版本(无论是发布版本还是最新草稿版本):


{% assign my_content = Content.Latest["alias:main-menu"] %}

 <font color=#0099ff size=4 face="黑体">{%assign my_content = Content.Latest [“alias:main-menu”]%}</font> 


Loading from a content item id

从内容项ID加载


{% assign my_content = Content.ContentItemId["417qsjrgv97e74wvp149h4da53"] %}

 <font color=#0099ff size=4 face="黑体">{%assign my_content = Content.ContentItemId [“417qsjrgv97e74wvp149h4da53”]%}</font> 


When a list of content item ids is available, the content_item_id filter should be preferred:

当内容项ID列表可用时,应首选content_item_id过滤器:


{% assign posts = postIds | content_item_id %}

 <font color=#0099ff size=4 face="黑体">{%assign posts = postIds | content_item_id%}</font> 


Loading from a content item version id

从内容项版本ID加载


{% assign my_content = Content.ContentItemVersionId["49gq8g6zndfc736x0az3zsp4w3"] %}

 <font color=#0099ff size=4 face="黑体">{%assign my_content = Content.ContentItemVersionId [“49gq8g6zndfc736x0az3zsp4w3”]%}</font> 


Razor Helper

剃刀助手

The following methods are available from the Razor helper.

Razor助手可以使用以下方法。

| Method | Parameters | Description |

|方法|参数|说明|

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

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

| GetContentItemIdByAliasAsync | string alias | Returns the content item id from its alias. |

| GetContentItemIdByAliasAsync | string alias |从别名返回内容项ID。 |

| GetContentItemByAliasAsync | string alias, bool latest = false | Loads a content item from its alias, seeking the latest version or not. |

| GetContentItemByAliasAsync | string alias,bool latest = false |从其别名加载内容项,寻求最新版本。 |

| GetContentItemByIdAsync | string contentItemId, bool latest = false | Loads a content item from its id, seeking the latest version or not. |

| GetContentItemByIdAsync | string contentItemId,bool latest = false |从其ID加载内容项,寻求最新版本。 |

| GetContentItemsByIdAsync | IEnumerable<string> contentItemIds, bool latest = false | Loads a list of content items by ids, seeking the latest version or not. |

| GetContentItemsByIdAsync | IEnumerable <string> contentItemIds,bool latest = false |按ID列出内容项列表,寻求最新版本。 |

| GetContentItemByVersionIdAsync | string contentItemVersionId | Loads a content item from its version id. |

| GetContentItemByVersionIdAsync | string contentItemVersionId |从其版本ID加载内容项。 |

The Razor Helper is accessible on the Orchard property if the view is using Orchard Core's Razor base class, or by injecting OrchardCore.IOrchardHelper in all other cases.

如果视图使用Orchard Core的Razor基类,或者在所有其他情况下注入OrchardCore.IOrchardHelper,则可以在Orchard属性访问Razor Helper。