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.

Template Questions

$Content.LimitCharacters - problem with special characters (in translation)


Reply

2 Posts   2132 Views

Avatar
koo_mikko

24 February 2012 at 8:57pm Community Member, 1 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
Avatar
Juanitou

24 February 2012 at 10:01pm Community Member, 323 Posts

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