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.

Template Questions /

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

String Manipulation in a Template


Go to End


3 Posts   6026 Views

Avatar
KeithLeslie

Community Member, 6 Posts

9 January 2009 at 6:37pm

I have a template that looks like this, that displays widget content from an RSS feed:

<% control GetBlogPosts %>
<p>
<a href="$URL" alt="Read $Title" target="_plain" >$Title</a><br>
$Body
</p>

<% end_control %>

Where the $Body is, I would like to only display 100 characters of the body that is returned by the control. My question is should I truncate the field in the widget or is there a way to do this in the templating engine?

Thanks in advance for your help.

Avatar
Liam

Community Member, 470 Posts

10 January 2009 at 7:35am

You can't do that in the template system. No programming aspects can be used in it, it is meant to go in your controller or page types.

Avatar
TT

Community Member, 6 Posts

10 January 2009 at 11:19am

Can you change the type of $Body to HTMLText? Then you can use the defined methods for this type (e.g. $Body.LimitWordCount(100))
http://doc.silverstripe.com/doku.php?id=HTMLText

Otherwise there is no chance :-)