Search code examples
htmlrazororchardcms

Orchard CMS: How to display a Layout Part in a view?


I'm trying to specify a different Query Layout for a query that returns several pages and completely take over the rendering of the list following this excellent guide: http://www.ideliverable.com/blog/ways-to-render-lists-of-things

I have the basic implementation setup and know it to be working by using the following simple code for the rendering:

@using Orchard.ContentManagement
@using Orchard.Core.Title.Models
@using Orchard.Layouts.Models

@{
  var webPages = ((IEnumerable<ContentItem>)Model.ContentItems).ToList();
}

@foreach (var wp in webPages)
{
  var titlePart = wp.As<TitlePart>();
  var wpTitle = titlePart.Title;

  <p>@T("{0} Title is ", wpTitle)</p>
}

Problem: However, when attempting to include the Layout of each page, I can't seem to work out how? Using the code below, only the text 'Orchard.Layouts.Models.LayoutPart' is rendered erroneously in the HTML.

  var layoutPart = wp.As<LayoutPart>();
  @Display(layoutPart)

Therefore, I'm assuming the LayoutPart is different to other common Parts in Orchard, because I have also tested many other parts which all successfully render, except Layouts (I'm thinking the LayoutPart has to be constructed somehow before being displayed, but that is clutching at straws)?

So how does one go about such?


Solution

  • Funnily enough, you're basically right. Layouts have to built before displaying:

    @Display(BuildDisplay(layoutPart, "#display type#")) //display type: Summary / Detail