Wrong Blog Title

Topics: Customizing Orchard, Troubleshooting
Jan 9, 2012 at 11:40 AM


I customize the Layout so that I display the Model.Title (same as Layout.Title?) outside the Content. While this works good for all pages, it displays a wrong title for a blog (not a blog post, but blog). Instead of the Blog Title it displays the title of the first blog post. 

When I debug I can see that Model.Title in Content-Blog.cshml has the right title, but in Layout.cshtml it shows the first blog post title.

Any ideas?

Jan 9, 2012 at 1:00 PM

It's to do with how that title gets to Layout.Title in the first place.

If you look at Orchard.Core\Contents\Views\Content.cshtml you'll see this at the start:

    if (Model.Title != null) {
        Layout.Title = Model.Title;

So this is where the content template pushes the content item's title up into the Layout shape. Any content items that render this template will overwrite Layout.Title.

Do you have the first blog post rendering in "Detail" or something like that? Or is this default behaviour of Orchard (therefore possibly a bug)?

Jan 9, 2012 at 1:29 PM

No, all posts are rendering in Summary. I've changed the placement.info to display the Body part instead of the Body_Summary, but that's for all posts, not just for the first one. I commented my placement.info for the test, but the title didn't changed, so we can say this is the default behavior of Orchard.

Jan 9, 2012 at 1:53 PM
Edited Jan 9, 2012 at 1:53 PM

It must be coming from somewhere; Content-Summary.cshtml doesn't set Layout.Title. Have you overridden any templates in your theme? You can also try a solution-wide search for "Layout.Title =".

Jan 9, 2012 at 2:04 PM

Got it! You are right - Content-Summary.cshtml doesn't set Layout.Title, but Content-BlogPost.Summary.cshtml does (which I have overridden).