This is going to drive me crazy at this rate. From inside of a Layout.cshtml file for a theme in Orchard, how can I determine the Title of the main body's contents?
I've tried using the Shape Tracer but it doesn't seem to help. None of these give me any text at all.
@Html.Title()
@Model.Title
@Model.Content.Parts_Common_Body.ContentItem.TitlePart
@Model.ContentItem.Parts_Common_Body.ContentItem.TitlePart
UPDATE: Here's the HTML which should show what the end result needs to look like to keep the theme intact, along with a picture showing the theme before I started with it. This HTML is just a snippet of the parts that I'm concerned with. In the picture, the search is what is in the ContentHeader zone.
<div id="wrapper-header-inner">
<div id="header-inner">
@Zone(Model.ContentHeader)
<h1 class="pagetitle">
Title Here
</h1>
</div><!-- #header-inner -->
</div><!-- #wrapper-header-inner -->
}
<div id="wrapper-content">
<div id="content">
@if(Model.Content != null) {
<div class="main" class="@mainContentClass">
@if(Model.Content != null && Model.LeftAside == null && Model.RightAside == null) {
<div id="maincontentFull" class="positionleft">
@Zone(Model.Content)
</div>
}
@* Other layout possabilities if left and/or right asides are present *@
</div>
}
</div>
</div>
As a follow up, updates to Orchard since I have asked this question included the ability to use the placement.info file to reroute certain parts to other zones, in effect letting me accomplish what I was looking for.
<Placement>
<Match ContentType="Page">
<Place Parts_Title="/TitleZone"/>
</Match>
</Placement>
From Layout, Model is the Layout object. It has nothing to do whatsoever with whatever content is going to get rendered into the Content zone, but it does have a Title property that should be set by that content. It is not exactly what you are asking for though: it is what will end-up being the HTML title.
If you want to get to the title of the item that gets rendered into the top-level Content zone, well, Layout is really not a good place to look for that. I would need to know more about what exactly you are trying to achieve but this seems backwards. In fact, you can't even assume that there is one such content item, or that there will be only one.
So what is it exactly that you are trying to do?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With