【问题标题】:Item Templates vs Part Templates in OrchardOrchard 中的项目模板与零件模板
【发布时间】:2013-10-15 15:06:25
【问题描述】:

我正在学习 Orchard,并参加了一些 Pluralsight 课程。它涵盖了部分模板,但现在我正在阅读这篇文章:Anatomy of a theme,其中有一个部分称为:Item Templates。我很困惑。我想我以前没有遇到过这个概念。有什么不同?让我们有一个示例,我有一个内容类型 Movie 和内容部分 Movie。我可以使用 Part Template 覆盖它的呈现方式。那么在这种情况下,我会在哪里使用 Item Template

【问题讨论】:

    标签: orchardcms orchardcms-1.6 orchardcms-1.7


    【解决方案1】:

    就这个问题写了一篇更详细的博文。无耻塞:http://arkleseizure.net/what-the-hell-is-an-item-template

    我同意措辞不是特别清楚。所以让我们看看我们能不能把这件事弄清楚……

    内容类型:电影

    • 标题部分
    • 导演部分
    • 工作室部分

    (所以你有一个名为电影的内容类型,附有 3 个部分)。

    我们希望所有部分都显示在详细视图中,而只有 TitlePart 显示在摘要显示中。所以我们使用placement.info

    <Match ContentType="Movie">
      <Match DisplayType="Summary">
        <Place Parts_TitlePart="Summary:1" />
        <Place Parts_DirectorPart="-" />
        <Place Parts_StudioPart="-" />
      </Match>
    
      <Match DisplayType="Detail">
        <Place Parts_TitlePart="Content:1" />
        <Place Parts_DirectorPart="Movie:1" />
        <Place Parts_StudioPart="Movie:2" />
      </Match>
    </Match>
    

    (为清楚起见使用显式符号)

    Placement 基本上定义了您的内容部分将放置在内容类型的位置。摘要、内容和电影是内容项中的“区域”,您可以将部分分配给这些区域,以便显示它们。所以让我们继续在一个名为 Content-Movie.Detail.cshtml 的文件中定义我们的内容和电影区域(这将是一个“项目模板”)。

    @using Orchard.Utility.Extensions;
    
    <article class="content-item">
      <div class="content">
        @Display(Model.Content)
      </div>
      <div class="content">
        @Display(Model.Movie)
      </div>
    </article>
    

    还有一个用于摘要,Content-Movie.Summary.cshtml

    @using Orchard.Utility.Extensions;
    
    <article class="content-item">
       <div class="content">
          @Display(Model.Summary)
       </div>
    </article>
    

    (您可以使用形状追踪工具 (http://docs.orchardproject.net/Documentation/Customizing-Orchard-using-Designer-Helper-Tools) 为您生成这些,它会创建默认区域(我相信是页眉、元、内容和页脚)和相关的 html。)

    我们的部件现在应该显示在正确的位置,我们可能想要更改标题的显示方式。所以我们可以创建一个“零件模板”,Parts.Title.cshtml

    <h1>Movie: @Model.Title </h1>
    

    总结一下。 内容类型由许多内容部分组成。 部件模板覆盖内容部件,项目模板覆盖定义了区域的内容类型的布局。 Placement.info 将内容部件定向到要显示的区域。

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多