Orchard - Getting the Content's Title from the Theme Layout
Asked Answered
F

3

8

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

Flooring answered 22/6, 2012 at 1:32 Comment(0)
F
4

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>
Flooring answered 13/12, 2013 at 17:44 Comment(0)
S
2

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?

Stoner answered 22/6, 2012 at 21:17 Comment(0)
S
0

Does this work for you?

@Html.Title()

That should work if you're looking for the page title. However, if you're looking to directly access the TitlePart...

@Model.Title

This works because if you look in the Parts.Title template there is a line of code that does this...

@{
   Layout.Title = Model.Title;
}
Saucer answered 22/6, 2012 at 4:11 Comment(7)
None of those give me the title. They don't even seem to have an output, I'm guessing they are SharpClay objects. Which as nice as they are for flexibility, are REALLY annoying to try and track down which properties/methods actually exist. It's like shooting into the air randomly and waiting to see if a bird falls from the sky.Flooring
Ya, it has it's trade-offs. I'm with Bertrand on this though, what are you trying to do? It does seem a bit backwards.Saucer
Well essentially I have a Theme that I'm trying to implement. And the theme I'm working with puts a div farther up the page DOM that holds the page's title. But because it's in a different location than the main page content I don't know how to place the Title there because it won't be a local zone in the Content zone, if that makes sense? I'll update the question with an example of the HTML in a minute...Flooring
But I'm looking for the Content title in this, not the HTML Title.Flooring
Well, if you can't make that part of the Content Zone, maybe you could use Bertrand's technique to put shapes in arbitrary zones: weblogs.asp.net/bleroy/archive/2011/03/26/…Saucer
I've seen that blog post but that seemed to be specifically pertaining to rendering the output of a custom part to a different zone, the Title is a built in part. I did at one point come across a post somewhere about using the placement file to render parts across zone boundaries, but I'll be damned if I can find it again.Flooring
@Yarx Right, but you can have more than one driver per part, so you can just add another driver for the TitlePart that performs this function.Saucer

© 2022 - 2024 — McMap. All rights reserved.