Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » $Content.LimitCharacters - problem with special characters (in translation)

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

Page: 1
Go to End
Author Topic: 1643 Views
  • koo_mikko
    Avatar
    Community Member
    1 Post

    $Content.LimitCharacters - problem with special characters (in translation) Link to this post

    Howdy folks

    I'm having this problem with limiting characters in latest news feature in a multilingual website.

    Everything seems to be working ok, except when the last character (ie. limit(10) and the 10 th character) is a special character. It produces character error. This weird question mark. Please see the attached screenshot.

    I've charset UTF-8 in _config and template files, so that seems to be ok. To be specific, i'm using scandic letters. Anyone has any ideas, or encountered this kind a behaviour before?

    Here's the code in page.ss:

    <% if News %>
    <% control News %>

    <div class="NewsFront">

    <h5><a href="$Link">$MenuTitle</a></h5>
    <p>$Content.LimitCharacters(80)</p>

    </div>

    <% end_control %>
    <% end_if %>

    And here's the function in page.php:

    function News($limit = 3) {
       $filter = 'StartPublish < NOW() AND EndPublish > NOW()';
       $order = 'Created DESC';
       return DataObject::get('NewsItem', $filter, $order, null, $limit);
    }

    Attached Files
  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: $Content.LimitCharacters - problem with special characters (in translation) Link to this post

    Hi!

    Yes, I’ve already seen it. I guess LimitCharacters is not UTF-8 compliant. I suggest you to find the function somewhere in sapphire (maybe the HTMLText class), put it in your Page class, study how it works and use where needed PHP functions as htmlentities(). You’ll maybe have to use Multibyte String Functions (http://www.php.net/manual/en/ref.mbstring.php).

    Sorry if I’m not being more specific, I’m not a PHP programmer.

    Hope it helps,
    Juan

    1643 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.