How to show the full blog post in the list

Topics: Core, Customizing Orchard, General, Troubleshooting
Oct 9, 2011 at 11:04 AM

When a blog is chosen, the list of blog posts is displayed. However only the first couple of lines of each post is seen. How can I show the full post or at least change the number of words or lines to be seen??

Coordinator
Oct 10, 2011 at 9:22 PM
Edited Oct 10, 2011 at 9:23 PM

Here is the Parts.Common.Body.Summary.cshtml template override that I use on my blogs:

@{ 
    Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
    var bodyHtml = Model.Html.ToString();
    var more = bodyHtml.IndexOf("<!--more-->");
    if (more != -1) {
        bodyHtml = bodyHtml.Substring(0, more);
    }
    else {
        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>@body</p>
<p>@Html.ItemDisplayLink(T("Read more...").ToString(), contentItem)</p>
Oct 10, 2011 at 9:30 PM

Can you please specify the location of the file in which the above code needs to be updated ?

Coordinator
Oct 10, 2011 at 9:39 PM

Just put it in the views folder of your theme.

Oct 10, 2011 at 9:46 PM

thanks - cud you please explain what exactly this code is doing ?

how many lines it is displaying ?

I have a picture and text in a blog post and by using this code, only picture is visible in the blog post and for rest it says, " Read more..."

Oct 10, 2011 at 9:50 PM

The code is very clear. It either grabs the first paragraph or the text from the beginning of the post up to "<!-more->". If you place this tag anywhere in your post, it will denote the end of the preview text.