Mr A
Mr A

Reputation: 6768

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 advance

Upvotes: 5

Views: 12557

Answers (3)

Danny Beckett
Danny Beckett

Reputation: 20848

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.

Upvotes: 0

Andrew
Andrew

Reputation: 67

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>
}

Upvotes: 2

marapet
marapet

Reputation: 56446

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

Upvotes: 6

Related Questions