果园中的项目模板与零件模板 [英] Item Templates vs Part Templates in Orchard

查看:81
本文介绍了果园中的项目模板与零件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Orchard,并且完成了一些Pluralsight课程.它涵盖了零件模板",但现在我正在阅读本文:主题的剖析,其中有一个部分:项目模板.我很困惑.我想我以前从未遇到过这个概念.有什么区别?让我们有一个示例,我的内容类型为电影,内容部分为电影.我可以使用零件模板覆盖它的呈现方式.因此,在这种情况下,我将在哪里使用项目模板?

I'm learning Orchard and I did some Pluralsight course. It covered Part Templates, but now I'm reading this article: Anatomy of a theme and there's a section called: Item Templates. And I'm confused. I think I haven't came across this notion before. What is the difference? Let's have a sample that I have a content type Movie with content part Movie. I can override how it's rendered using Part Template. So where I would use Item Template in this case?

推荐答案

写了一篇有关此问题的博客文章,其中包含了更多细节.无耻的插件: http://arkleseizure.net/what-the-hell-是一个项目模板

Wrote a blog post with a tiny bit more detail in regards to this question. Shameless plug: http://arkleseizure.net/what-the-hell-is-an-item-template

我同意这个措词不是特别清楚.因此,让我们看看是否可以清除此问题...

The wording is not particularly clear I would agree. So let's see if we can clear this up a little...

内容类型:电影

  • 标题部分
  • DirectorPart
  • StudioPart

(因此,您有一个称为Movie的内容类型,其中附加了3个部分).

(So you have a content type called movie with 3 parts attached to it).

我们希望所有零件都显示在详细信息视图中,而只有TitlePart才显示在摘要"显示中.所以我们使用placement.info

We want all the parts to be displayed in the detail view and only the TitlePart displayed in the Summary display. So we use 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>

(为清楚起见,使用了明确的符号)

(Explicit notation used for clarity)

放置基本上定义了内容类型将放置内容部分的位置.摘要,内容和电影是您为其分配零件的内容项目中的区域",以便可以显示它们.因此,让我们继续在名为Content-Movie.Detail.cshtml的文件(这将是项目模板")中定义内容"和电影"区域.

Placement basically defines where your content parts will be placed for a content type. Summary, Content and Movie are "zones" within a content item that you assign parts to so they can be displayed. So let's go ahead and define our Content and Movie zones in a file called Content-Movie.Detail.cshtml (This would be an "Item Template").

@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

And one for summary, 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.)

(You can use the shape tracing tool (http://docs.orchardproject.net/Documentation/Customizing-Orchard-using-Designer-Helper-Tools) to generate these for you and it will create default zones (Header, Meta, Content and Footer, I believe) and the relevant html.)

现在我们的部件应该显示在正确的位置,我们可能需要更改标题的显示方式.这样我们就可以创建一个零件模板" Parts.Title.cshtml

Our parts should now be displaying in the right places and we may want to change how the title is displayed. So we can create a "Part Template", Parts.Title.cshtml

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

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

So in summary. Content Types are made up of lots of Content Parts. Part Templates override the Content Parts and Item Templates override the layout of a Content Type where Zones are defined. Placement.info direct Content Parts to the zones to be displayed.

希望有帮助!

这篇关于果园中的项目模板与零件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆