This project is read-only.

ContentPart Rendering

Nov 11, 2010 at 2:32 PM
Edited Nov 11, 2010 at 2:39 PM

First of all, You guys rock!!


Using 0.8 version,

I am trying to figure out how to render my "Article" ContentPart without rendering certain parts (e.g. Comments), that were specified in my Content Type definition (Migrations.cs) like Comments.

What gets rendered is my Articles.Article.Item.cshtml part followed by BodyPart and CommentPart renditions. I would like to eliminate the rendition of Comments.

Like you can clearly see I am really trying to explain the issue :)


GET http://localhost/Orchard.Web/Articles (routed to List() action in ArticleController.cs)




public ActionResult List()
            var list = Services.New.List();
                              .Select(a =>
                                  var article = Services.ContentManager.BuildDisplay(a);
                                  return article;

            var viewModel = Services.New.ViewModel()

            return View(viewModel);





protected override DriverResult Display(ArticlePart part, string displayType, dynamic shapeHelper)
            return Combined(
                                () => shapeHelper.Parts_Articles_Article_Item(ContentPart: part))



@if (Model.ContentItems.Items.Count < 1) {
<p>@T("No articles found.")</p>


<h1> @Display(Model.Header) </h1> by @Display(Model.ContentPart.Author) <p>LEAD</p> <p>@Display(Model.ContentPart.Lead)</p> CONTENT <p>@Display(Model.ContentPart.Text)</p> CONCLUSION <p> @Display(Model.ContentPart.Conclusion) </p>


Nov 11, 2010 at 8:12 PM

Instead of calling @Display(Model.ContentItems), you should be able to loop through them yourself and specify exatly what you want to render, or you should be able to override the rendering for that combined shape.

Feb 1, 2011 at 4:18 AM

Hi i am new on Orchard, Can you please help me. I am trying to modify orchard blogs. By default orchard blogs showing two line of any post without any image. I want to show near 10-15 lines along with an image. What i need to do to achieve this.

I have tried also tried as per above post but nothing works for me.

Any help will be appreciated...

Feb 1, 2011 at 4:22 AM

Here's the Parts.Common.Body.Summary.cshtml template that I'm using in the Views folder of my theme:

    Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
    var bodyHtml = Model.Html.ToString();
    var firstP = bodyHtml.IndexOf("<p>");
    var firstSlashP = bodyHtml.IndexOf("</p>");
    if (firstP >=0 && firstSlashP > firstP) {
        bodyHtml = bodyHtml.Substring(firstP, firstSlashP + 4 - firstP);
    var body = new HtmlString(bodyHtml); 
<p>@Html.ItemDisplayLink(T("Read more...").ToString(), contentItem)</p>

Feb 1, 2011 at 5:03 AM

Thanks bertrandleroy for your reply. But i am still not very clear about the solution. I am explaining it in detail:

@{    IEnumerable<object> blogPosts = Model.ContentItems;  





@if (blogPosts == null || blogPosts.Count() < 1)

{<p>@T("There are no posts for this blog.")</p>}

This is taken from Parts.Blogs.BlogPost.List.cshtml

In this (in bold) Model.ContentItems are showing me whole details of my blog along with contents section. But i want to show only blogpost not comments.

Is there any such way like (eg: @Display(Model.Header) </h1> by @Display(Model.ContentPart.Author) <p>LEAD</p> <p>@Display(Model.ContentPart.Lead)</p> CONTENT <p>@Display(Model.ContentPart.Text)</p>)

i have tried this example too. but nothing works.

Thanks in advance.

Feb 1, 2011 at 5:09 AM

I'm sorry but you are confusing me. What exactly are you trying to do?

Feb 1, 2011 at 5:17 AM

i am saying if i write @Display(Model.ContentItems) in my BlogPost.List.cshtml. It is showing whole blog posts along with comments too.

I want only blog posts not comments. I want to remove comments section from here. Is there any such way that i render only blogposts content not comments. 


Feb 1, 2011 at 5:35 AM

Right, it seems like you don't have a reason to override BlogPost.List.cshtml here but should instead override the summary template for the posts.