Developer forum

Forum » CMS - Standard features » How can i use *.StripHtml()‎ in Razor

How can i use *.StripHtml()‎ in Razor

Hans Ravnsfjall
Reply

Hi

I have a Razor tag, where i want to publish first 260 Characters, but i want it to not output nordic charachters as broken  - look at some of the endings of the newselements on this page, where the chars are broken. http://heilsurokt.net.dynamicweb-cms.com/oell-tidindi

 

How do i make shure in razor, that these chars are not broken or not html´ized? I think I recall that I have used StripHtml() for this in regular templates.

 

This is the loop

 

@Include("includes/NewsList.cshtml")

<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">            
        <h3 class="dw-section-title"><span>@GetGlobalValue("Global:Page.Name")</span></h3>
    </div>
</div>
<section class="slice">
    <ul class="list-listings blog-list">
        @GetNewsList(GetLoop("ItemPublisher:Items.List"), 260)
    </ul>
</section>


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Hans

StripHtml is a tag extension method - and they only work for the HTML based template tags.

But you can do this using C#.

In Includes/NewsList.cshtml add the second line below:

string Description = newsitem.GetString("ItemPublisher:Item.Text");
Description = System.Web.HttpContext.Current.Server.HtmlDecode(Dynamicweb.Base.StripHTML(Description));

It will strip the html and them decode the non-ascii characters and then the truncate should work as intended.

BR Nicolai

Votes for this answer: 2
 
Hans Ravnsfjall
Reply

Works perfectly thank you :)

Happy New Year

regards, Hans

 

You must be logged in to post in the forum