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

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


Go to End


2 Posts   8569 Views

Avatar
koo_mikko

Community Member, 1 Post

24 February 2012 at 8:57pm

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

Community Member, 323 Posts

24 February 2012 at 10:01pm

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