This project is read-only.

Modification in Orchard summary template

Feb 7, 2011 at 9:22 AM

Hi Professionals,

I am working on Orchard cms in Parts.Common.Body.Summary.cshtml. Following is the default functionality:

   Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;

    string bodyHtml = Model.Html.ToString();

    var body ="";

var body = new HtmlString(Html.Excerpt(bodyHtml, 400).ToString());

MY Problem: Excerpt function (wordpress function) is used to remove all the html tags from string (here bodyhtml).It means they are not rendering html tags from here. i want my program render html tags. because i want to show image also. For this if i remove the "Excerpt" function. Then system doesn't render my html tags. it shows it as a string.(it is showing in this format: <div style=""><img src="test.jpg"></img>sample text</div>). what and where should i do some thing so that it renders my html tags.

Feb 7, 2011 at 7:17 PM

You'll need to create a new HtmlString with the markup that you want in the summary, like the assignment to the body var above but with whatever you need in the summary instead. This way the markup won't be encoded when rendered.

Feb 7, 2011 at 8:16 PM

Here's what I use on my site, which takes the first paragraph with all markup. You can also look for a specific marker if you want or use whatever criteria suits your need:

    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>
This is Parts.Common.Body.Summary.cshtml and it lives in the Views folder of my theme.

Feb 8, 2011 at 5:14 AM

Thanks for reply guys. 

I have tried above solution also but it was not work. so i did some work in DisplayManagement.Descriptors.ShapeAttributeStrategy to decode the html tags.

boom it will work for me. Thanks for your great support.





Mar 30, 2011 at 3:48 PM

And if instead using the Body, i'll choose to use HtmlField... it works the same way? I can't getting it to work...

Mar 30, 2011 at 9:36 PM

I'm not sure what you mean. Can you give more details about what you are trying to do?