This project is read-only.

why does my html get stripped from my blog posts?

Topics: General
May 16, 2011 at 11:07 PM
Edited May 17, 2011 at 1:54 PM

hi - i'm new to orchard. but why does my html (images, etc) get stripped from my blog posts when displaying my main blog (recent posts) page? more importantly, how do i get the code back? 

for example, i want my main post image to show up with my images; not just my text.

May 16, 2011 at 11:12 PM
Edited May 16, 2011 at 11:14 PM

Here is the Parts.Common.Body.Summary.cshtml that I use in the Views folder of my theme:

    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>@Html.ItemDisplayLink(T("Read more...").ToString(), contentItem)</p>

This will cut the text wherever you put a <!--more--> marker in the post's HTML, or it will take the first paragraph. If it can't find the first paragraph, it will use the full post.

You should be able to adapt that to exactly what you need.

May 17, 2011 at 1:56 PM

thanks very much for your reply. i edited my original post due to a type-o. i meant i wanted to show things like my images not just my text.

for some reason orchard takes my blog post and removes all formatting including images to display on the 'recent blog posts' section (the main blog page). 

any ideas why/where it does this and how to get it back?

May 17, 2011 at 2:10 PM

The point here is that you can write your own Parts.Common.Body.Summary.cshtml that displays the full rendering instead of the summary view. If you look at the built-in Parts.Common.Body.Summary.cshtml in Orchard.Code\Common\Views you'll see how it's processing the HTML to produce the brief.

May 17, 2011 at 2:16 PM
Edited May 17, 2011 at 2:51 PM

excellent that's exactly what i needed to know. thanks!

it's in Orchard.Core... but i knew what you meant. :)

only one weird thing.... my <img tag is at the beginning of my content block and yet it's still getting stripped. very strange. because the code you mentioned looks like it's going from 0 to 200 and then cutting off. guess i'll just have to poke around a bit more.

thanks for pointing me in the right direction.


edit: i'm guessing Html.Exerpt does the stripping of html.

May 17, 2011 at 6:01 PM

Yes: as you can see, my code is using Model.Html instead.