Where does Model.Header get rendered to?

Topics: Customizing Orchard, Writing modules, Writing themes
Aug 26, 2011 at 4:43 PM

In the Content.cshtml template there is a line:

@Display(Model.Header)

Two of us have tried all manner of combinations of

Zone-Content.Header.cshtml

Content.Header.cshtml

[ContentType].Header.cshtml

etc.

Also using nothing, - and _ where the . are above.

 

Could anyone help identify how to change how it gets rendered? :)

Coordinator
Aug 26, 2011 at 6:50 PM

What is shape tracing telling you? Also, can you give more details about what you're trying to do?

Aug 26, 2011 at 9:44 PM

Shape tracing is saying that it's Parts_RoutableTitle, but there is more being rendered than it look like there should be (from the routable title template and content template).

We'd like to modify the header tag from the defualt content.cshtml to allow for sub headers etc.

Coordinator
Aug 26, 2011 at 9:47 PM

So what you are really trying to do is add more shapes to the local header zone? Or add an additional zone?

Aug 26, 2011 at 9:53 PM

Um yes...

I'm having ah-ha moments on a daily basis with Orchard now, and I think I'm really starting to understand it, but I'm still not sure how to do such obvious things! :) 

How do I tell it to render to the Model.Header defined in Content.cshtml instead of the Zone header? And if I wanted to change the html, which file would I need to add to the theme?

Coordinator
Aug 26, 2011 at 9:57 PM

What's "it"? :) I'm sure if you give me a little more details, I'm going to be able to guide you...

Aug 26, 2011 at 9:58 PM

Any random shape or model property

Coordinator
Aug 26, 2011 at 10:07 PM

Placement.info should work for that.

Aug 26, 2011 at 10:22 PM

How do you put a single property from a part into placement.info?

And for that matter :) how do you put a shape into placement.info?

Coordinator
Aug 26, 2011 at 10:28 PM

If you only have a single property to place, you'll have to do that in code. It's as simple as doing Add on the zone.

Alternatively, you can stick that property onto a custom shape and send that shape anywhere, from code or from placement.

I do not understand the statement "how do you put a shape into placement.info": a place tag in placement.info has attributes that are named like shapes and have values indicating what zone to send them to.

Aug 26, 2011 at 10:30 PM

Thanks again.

I think I've developed some kind of code blindness :)

I've been thinking about placement.info as a list of parts, but it's not. It's a list of shapes. And I knew that, it just didn't register.

But hopefully all in now

Aug 28, 2011 at 12:47 PM

Hi, I'm the other Carl working on this. quite new to Orchard (as in a few days).

Content.cshtml contains the following:

...
<article class="content-item @contentTypeClassName">
    <header>
        @Display(Model.Header)
        @if (Model.Meta != null) {
        <div class="metadata">
            @Display(Model.Meta)
        </div>
        }
    </header>
    @Display(Model.Content)
...

What I am having trouble with is how "@Display(Model.Header)" is rendered. "Header" looks like it is a zone - which could then presumably be overridden and customized, but I haven't established, via shapetracing, what zone this is or how to do this. Shapetracing only shows the shapes that are being rendered into this zone (it seems, by default, Parts_RoutableTitle and Parts_Tags_ShowTags). So we want to customize inside this header tag to display other elements (a background image, article author name and role, etc.) and for what to display also to depend on the content type (some have no background image, or author).

What would be the best way to go about this? It feels like I'm missing something quite trivial...

Cheers,

CarlL

Aug 28, 2011 at 1:32 PM
bertrandleroy wrote:

If you only have a single property to place, you'll have to do that in code. It's as simple as doing Add on the zone.

Alternatively, you can stick that property onto a custom shape and send that shape anywhere, from code or from placement.

I do not understand the statement "how do you put a shape into placement.info": a place tag in placement.info has attributes that are named like shapes and have values indicating what zone to send them to.

so, I can override Content.cshtml and add the following inside the header tag:

...    
<header>
        @Display(New.TestHeaderShape())
...

and then I can use the file Views\TestHeaderShape.cshtml to customize what goes in the header tag? or make different header shapes for each content type and switch them on/off with placement.info?

Developer
Aug 28, 2011 at 1:38 PM

Hey All, best way to do this in my opinion is to use the Placement.info file... You can then do this,

<Placement>
  <Match ContentType="Forum">   
    <Match DisplayType="Detail">
      <Place
            Parts_Forums_Forum_Status="Header:1"/>
    </Match>
    <Match DisplayType="Summary">
    </Match>
  </Match>

using the placement.info file you can also limit on content type. (I have just used an example from my forum module)

Does this help?

Aug 28, 2011 at 3:57 PM

yes, i think that's what i want to do. use placement.info to render a few fields from the model, but in the header rather than after it. so they should be shapes in order to do this? your Parts_Forums_Forum_Status is a shape. how did you do that? can you give some more of the code to make that work?

Thanks

Developer
Aug 28, 2011 at 4:00 PM

Sure, so

In my ForumPartDriver.cs You all you need to do is have this...

        protected override DriverResult Display(ForumPart forumPart, string displayType, dynamic shapeHelper) {
            var latestPostPart = _postService.GetLatestPost(forumPart, VersionOptions.Published);
           
            return Combined(
                ContentShape("Parts_Forums_Forum_Status",
                             () => shapeHelper.Parts_Forums_Forum_Status(ContentPart: forumPart)),

 

and also have the Parts.Forums.Forum.Status.cshtml file iwthin the Views folder.

Then your placement info class tells you where to put it.

Check out the code on orchardforums.codeplex.com hopefully it should help :)