Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

LimitWordCount strips out html?


Go to End


2 Posts   2053 Views

Avatar
Ryan M.

Community Member, 309 Posts

11 May 2011 at 8:52am

I found that using LimitWordCount on a HTMLText field, such as: $Content.LimitWordCount(20) tends to strip out any html elements within and the result is:

<dd>Check out this review from
CraveOnline[http://www.craveonline.com/film/articles/167047-thats-what-i-am-review]
for my latest film, THAT'S WHAT I AM.  Opens in limited
release on April 29, 2011 and...</dd>

Is there any other HTML-friendly method I can use instead, or is there a work-around for this?

Avatar
swaiba

Forum Moderator, 1899 Posts

11 May 2011 at 9:48pm

Edited: 11/05/2011 9:48pm

it doesn't seem to, it does - in order to count the number of words it removes the html code. It's not very straight forward I did write out some pseudo code but due to not being able to see my previous posts I cannot find it. The main concern is if you have a html like this...

<table><tbody><tr><td>This is more than five words right here</td></tr></tbody></table>

And then you get the first 5 words... it could damage the structure of your HTML displayed ont eh page very badly. Still very intrested in a solution... if there is one...