Orchard Core 文档翻译 (五)自动路由 Autoroute (OrchardCore.Autoroute)

Autoroute (OrchardCore.Autoroute)

此模块允许您为内容项指定自定义URL(永久链接 permalink)。

Autoroute Part

将此部分附加到内容类型以指定内容项的自定义URL。

然后,转到内容类型的定义并编辑 Autoroute Part:

  • 使用Liquid表达式输入Pattern,该表达式将表示生成的slug。 

具有TitlePart的内容的示例将使用它来生成slug:

{{ ContentItem | display_text | slugify }} 

具有ListPart和TitlePart(ig:BlogPost嵌套在博客中)的内容示例将使用容器和标题生成slug:

{{ ContentItem | container | display_text | slugify }}/{{ ContentItem | display_text | slugify }}`
  • 如果您希望在编辑内容项时能够输入自定义路径,请选中“Allow custom path”。
  • 如果您希望能够将内容项目设置为主页,请选中 'Show homepage options'

Autoroute Alias

只要您可以通过别名检索内容,就可以通过URL检索具有Autoroute的内容项(请参阅下面的示例)。这个语法是 slug:<URL>, e.g. slug:my-blog/my-blog-post.

Liquid

启用Autoroute后,您可以在liquid 视图和templates中按URL检索内容:

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

or

{% assign my_content = Content.Slug["my-blog/my-blog-post"] %} 

猜你喜欢

转载自www.cnblogs.com/Qbit/p/9746468.html
今日推荐