I took over the rendering of the list in Orchard in order to be able to create my own markup (I need to create an interactive navigation to the actual contents of the list). This is the code I'm currently using:
@using Orchard.DisplayManagement.Shapes;
@{ var list = Model.List; var items = list.Items; var count = items.Count; var listTag = Tag(list, "ul"); listTag.AddCssClass("historia"); var index = 0; } <div class="produtos"> @foreach (var item in items) { var itemTag = Tag(item, "div"); itemTag.AddCssClass("item-" + index); @itemTag.StartElement; <h3> @item.Title </h3> <p>@item.MyCustomTextField</p> @itemTag.EndElement; ++index; } </div> @Display(Model.List) @Display(Model.Pager)
It almost works ... I cannot access the fields of the list of elements ... I want to grab the heading and put it in h3 and then put the custom text field in the paragraph following it ... I will use CSS to display it correctly this part of the navigation. After this part of the navigation, I will call the standard list rendering procedure.
The problem is that @ item.Title gives the string null / empty. I want to access the contents of an element (no pun intended), which includes a custom text field, which is an excerpt for the entire message that will be displayed in the "navigation bar".
Bertrand shows us how to do this with blog posts:
@using Orchard.ContentManagement; @{ IEnumerable<object> blogPosts = Model.ContentItems.ContentItems; } @if (blogPosts == null || blogPosts.Count() < 1) { <p>@T("No posts.")</p> } else { <ul class="content-items"> @foreach (dynamic post in blogPosts) { string title = post.Title; ContentItem item = post.ContentItem; <li class="content-item-summary"> @Html.ItemDisplayLink(title, item) </li> } </ul> }
But it does not work the same with standard lists.
(Another small question: could / should I use a custom wrapper instead of overriding the entire layout for this list?)
source share