Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orchard - Getting the Content's Title from the Theme Layout

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>

Snapshot of the resulting layout

like image 737
Nick Albrecht Avatar asked Jun 22 '12 01:06

Nick Albrecht


2 Answers

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>
like image 101
Nick Albrecht Avatar answered Oct 18 '22 19:10

Nick Albrecht


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?

like image 37
Bertrand Le Roy Avatar answered Oct 18 '22 21:10

Bertrand Le Roy