This project is read-only.

Creating a new recent blog post widget

Dec 28, 2010 at 6:20 PM

The recent blog post widget formats things in a strange way, by replacing all list items with a paragraph. So I wanted to create a new widget that just displays the title of each item. Where is this formatting of the content list occurring? And what are the parts needed to create a new widget? It's a bit confusing looking at the Blog Module determining how this fits together.

Thanks in advance,

Dec 29, 2010 at 6:11 AM

No need to create a new widget. You just need to override the template in your theme. Parts.Blogs.RecentBlogPosts.cshtml seems like a good place to start.

Dec 29, 2010 at 8:32 PM

So it looks like the formatting is controlled by the Parts.Common.Body.Summary.cshtml which is the generic "content summary" display template. 

When I override the Parts.Blogs.RecentBlogPosts.cshtml, I am trying to break 



Into its individual components. Wouldn't that look something like below? 

<div style="border:solid 1px red;">
  @foreach(var item in Model.ContentItems) {
   <p>@Html.ItemDisplayLink(T(item.Name.ToString()).ToString(), item)</p>

Thanks for your patience, I'm new to both Orchard and Razor.




Dec 29, 2010 at 9:58 PM

Yes, that looks about right.

Jan 6, 2011 at 4:31 AM

Unfortunately, the ItemDisplayLink doesn't seem to be available in the Theme project. Also, if I get rid of it and just try and display item.Name.ToString() without the link nothing shows up. All I get is the red outline.

Does anyone have working example of overriding the Parts.Blogs.RecentBlogPosts.cshtml to get better control over how the content is displayed?

Thanks in advance,

Jan 6, 2011 at 2:50 PM

ItemDisplayLink is an extension method. Maybe you need to add a using for Orchard.Mvc.Html, though it is added by defaut in the web.config.

May 4, 2011 at 10:23 AM
ItemDisplayLink is extension method and passed "var item in Model.ContentItems" is not IContentItem so there is no such signature for ItemDisplayLink.

I've also wanted to have last 5 titles of blog posts only. Here is my solution in my custom theme.


@using Orchard.ContentManagement;
@using Orchard.Utility.Extensions;
@using Orchard.Blogs.Models;
@using Orchard.Core.Routable.Models;
    var count = Model.ContentItems.ContentItems.Items.Count;

  (t, i) =>
      return MvcHtmlString.Create(
@"    <article class=""content-item blog-post"">
    "blog-posts content-items")

May 4, 2011 at 6:21 PM

The String.Format part is quite ugly seeing how easy it is to do the same thing with the plain Razor syntax. See