This project is read-only.

Placement of part in header

Topics: Writing modules
Jul 13, 2011 at 9:47 PM

Hi, I'm trying to place my custom created part to the header zone but with no succes. The following doesn't work for me:

<Place Parts_TestHeader="Header:1"/>

Jul 13, 2011 at 11:47 PM

What happens when you try?

Jul 14, 2011 at 8:33 AM

It disappears or it is only visible in the content zone.

Jul 14, 2011 at 6:08 PM

i also tried it with:

_workContextAccessor.GetContext().Layout.Zones["Header"].Add(shape, "1");

but now it renders in the header: Orchard.ContentManagement.Drivers.ContentShapeResult
Jul 14, 2011 at 7:19 PM

The code with the layout is going to send your shape into top-level zones, which is apparently not what you're looking for. Please check that the content template that you are using (typically content.cshtml or some alternate of that, in your theme) does have a Header local zone defined.

Then again, I'm confused: you are saying "it disappears or it is only visible in the content zone". Which is it? And isn't it what you want that it displays in the Header local zone under the top-level Content zone? That's what seems to be implied as when it displays in the header when you user the Layout code above, you do not seem to be satisfied either. Can you please detail what exactly you are trying to obtain?

Jul 14, 2011 at 7:58 PM

Thanks for the support bertrandleroy!

Ok i wasn't really clear with my question by saying "it disappears or it is only visible in the content zone".

What i meant to say within the first question is that i tried some placements and the following placement moved the part only to the first place of the Content zone:

<Place Parts_TestHeader="Header:1"/>

Other attempts made it disappear (probablly because i used unkown zones in the placement.

using the following: _workContextAccessor.GetContext().Layout.Zones["Header"].Add(shape, "1");

results in rendering the following in the header: ContentManagement.Drivers.ContentShapeResult

Finally i managed to get ik working the way i want by adding the following line of code in my Layout.cshtml in the theme:
WorkContext.Layout.Header.Add(New.Parts_TestHeader(), "10");

Even though it works i still don't know if this is the best way to this.
To clear out my question: I have a custom part which i'm trying to render in the Header zone above the Website logo.
Jul 14, 2011 at 8:28 PM

That last code you have is a perfectly valid way of doing things. The reason why the code above that was not rendering is that "shape" there is actually not a shape, it's a shape result. You would have needed to extract the shape out of it. But your last code is just fine. You can even pass in data by adding parameters: New.Parts_TestHeader(Foo: "bar").

Jul 14, 2011 at 8:44 PM

Ok but i still have a problem with my part in the Header Zone. I can see it's getting renderen in the Header Zone but the content doesn't show up. When i use:

WorkContext.Layout.Header.Add(New.Parts_TestHeader(), "10");

The content is not showing. When i don't use that rule but render it in the content Zone it does show content. Any clue?
Jul 14, 2011 at 10:16 PM


I used Designer Tools Create Parts.CulturePicker.cshtml, and now I want to add it my layout. I am using the Terra theme. I am trying to add it as an Ad-Hoc shape... Any ideas?

WorkContext.Layout.Header.Add(New.Parts.CulturePicker(), "4") is what i added...


Jul 15, 2011 at 9:32 AM
Edited Jul 15, 2011 at 10:19 AM

@xotj123 please create a new discussion for your question because this is a different question. Thanks!

Jul 15, 2011 at 8:15 PM

i believe i am trying to place a part in a header, LOL, but I solved, it thanks....

Jul 16, 2011 at 6:40 PM


Jan 24, 2012 at 3:21 PM

Now you can do this from