开发者

how to remove html tags from rich text editor in Umbraco (Razor)

I am using a rich text editor to display description on the products page , but the page renders as :

<p>text description</p>

The macro for description is :

Razor syntax:

@foreach ( var page in @Model.Children)
{


    <div id="productSection">
  <div id="productstext">

  <div id="image">
  <a href="@page.Url"><img src="@page.productImage" height="200px" width="230px"/></a> </div>
 <div id="title">
  <h3>@page.GetProperty("productTitle") </h3> </div>

<div id="description">

 @page.GetProperty("product") </div>
 </div>
 </div>
} 

Thnx in adva开发者_如何学Cnce


If the question is how to remove the paragraph tag which is rendered around the rich text, you may try the whether the following solution works for you:

@umbraco.library.RemoveFirstParagraphTag(page.product.ToString())

You may want to wrap that in a helper:

@helper RemoveParagraph(HtmlString s)
{
    @Html.Raw(umbraco.library.RemoveFirstParagraphTag(s.ToString()))
}

and then call id like this:

@Helpers.RemoveParagraph(page.product)

Be aware though that umbraco.library.RemoveFirstParagraphTag also removes line breaks (which most of the time is not a problem).

See also the Umbraco forum post about exactly this question: http://our.umbraco.org/forum/developers/razor/19379-Remove-paragraph-tags-with-razor


We ran into this same problem on one of our projects and solved it with this simple way of doing it. Wrapping the value with an "@Html.Raw()" fixed the issue.

<section class="links">
@{
    var Link = Model.Content.Descendants("links");

    <ul>
        @foreach (var links in Link)
        {
            <li data-category="@(links.GetProperty("weblinkCategory").Value)">
                <a href="@(links.GetProperty("weblinkAddress").Value)">
                    @(links.GetProperty("weblinkTitle").Value)
                    <span>@Html.Raw(links.GetProperty("weblinkDescription").Value)</span>
                </a>
            </li>
   }
    </ul>
}


Umbraco 8 has removed the deprecated method RemoveFirstParagraphTag.

Instead you can use:

@Html.Raw(Model.Content.ToString().Trim().Substring(3).Substring(0, Model.Content.ToString().Trim().Length - 7))

Where Content is the name of your Property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜