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.

Customising the CMS /

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

HTMLText Question


Go to End


3 Posts   2838 Views

Avatar
DanStephenson

Community Member, 116 Posts

7 March 2009 at 6:11am

Hello,

I am reading the documentation on HTMLText useage in a template (http://doc.silverstripe.org/doku.php?id=htmltext), and was wondering if I can combine some of the different displays.

For example, what if I wanted to display the first 10 words, but strip out all HTML. Could I use something like

$Content.NoHTML.LimitWordCount(10)

What I am finding, by just using the LimitWordCount, is that bold text is appearing with a ** around it, which I'd like to avoid for this display.

Avatar
Ingo

Forum Moderator, 801 Posts

15 March 2009 at 8:16am

Nope, you can't chain these commands in the template. Workaround: Make a custom controller method, e.g.
function ContentNoHtmlLimitWordCount() {
$content = $this->obj('Content')->NoHTML();
return $content->LimitWordCount(10);
}

Ugly, but does the job...

Avatar
Sam

Administrator, 690 Posts

15 March 2009 at 2:00pm

I've added a ticket describing a fix that will make it easier to change NoHTML and LimitWordCount - http://open.silverstripe.com/ticket/3728