Overwriting BlogPost.List Template

Topics: Customizing Orchard, Writing themes
Feb 11, 2013 at 1:01 PM
Hi, I need to create a template to overwrite the blog post list for a specified blog as I will have more than one. So I have created the below template in Views/Parts but it will affect all blogs.


Here are the information of the blog.

Blog: /Admin/Blogs/1034/Edit
Blog Url: /About-Us/Company-News

Thanks in advance
Feb 11, 2013 at 4:16 PM
Feb 13, 2013 at 6:03 AM
I used the example in http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx and put a breakpoint in the custom view for Parts.Blogs.RecentBlogPosts.cshtml and find out that string title = post.Title; is null as a result the following code that displays the url extracts the title from the item variable. Can you please provide an example how I can retrieve foreach post, date published and body(post description) so I can get a clear picture how this works? I tried several time getting those information but with no success and I would really like to know how to achieve this.

ContentItem item = post.ContentItem;
    <li class="content-item-summary">
        @Html.ItemDisplayLink(title, item)
Feb 13, 2013 at 7:43 AM
You can get the parts from any item if you know the names of those parts. If you cast item to dynamic, then you can do item.TitlePart.Title, or item.BodyPart.Text.
Feb 13, 2013 at 8:58 AM
Edited Feb 13, 2013 at 8:59 AM
thank you, its working fine now. in addition to this, what is the best way to find out all the Parts and the correct path for a specific ContentItem, as an example is BlogPosts title path is item.TitlePart.Title. Also I used Shape Tracing but I did not find anything related to this.
@using Orchard.ContentManagement;
    IEnumerable<object> blogPosts = Model.ContentItems;

<div class="internal-content">
    <h1 class="first-title">@T("Company News")</h1> 
    <div id="separator">&nbsp;</div>
    @if (blogPosts == null || blogPosts.Count() < 1) {
    <p>@T("There are no posts for this blog.")</p>
    else {
        <ul class="content-items">
        @foreach (dynamic post in blogPosts) {        
            dynamic item = post.ContentItem;
            string title = item.TitlePart.Title;
            string body = item.BodyPart.Text;            
            <li class="content-item-summary">
                @Html.ItemDisplayLink(title, (ContentItem) item)
Feb 13, 2013 at 9:48 PM
Url.ItemDisplayUrl(someContentItem) gives you the url. contentManager.GetItemMetadata(contentItem).DisplayText gives you the title.
Feb 14, 2013 at 11:09 AM
Exactly, and there's an Html helper for the latter as well: