質問

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?

役に立ちましたか?

解決

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...

Content Type: Movie

  • TitlePart
  • DirectorPart
  • StudioPart

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

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)

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>

And one for summary, Content-Movie.Summary.cshtml

@using Orchard.Utility.Extensions;

<article class="content-item">
   <div class="content">
      @Display(Model.Summary)
   </div>
</article>

(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.)

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>

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.

Hope that helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top