Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » String Manipulation in a Template

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

Page: 1
Go to End
Author Topic: 2788 Views
  • KeithLeslie
    Avatar
    Community Member
    6 Posts

    String Manipulation in a Template Link to this post

    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.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: String Manipulation in a Template Link to this post

    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.

  • TT
    Avatar
    Community Member
    6 Posts

    Re: String Manipulation in a Template Link to this post

    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

    2788 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.