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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS 3.1 and un-english characters in template


Go to End


6 Posts   876 Views

Avatar
folibis

Community Member, 13 Posts

8 December 2014 at 2:39pm

Edited: 08/12/2014 2:39pm

I installed fresh SS package via composer. The site,DB and all other stuff in UTF-8
Ok, it works great.
Now I insert single word in themes/simple/Page.ss in un-english charset, in my case it was Russian word "тест".
After that the main page looked screwed up, I see "тестстт�" instead of "тест" and all the remainder of the page after this word just disappeared.

Ok, it looks like a bug and I placed issue on Github.
But how can I solve this problem just now? My site is closed now so I need a temporary solution or advice or maybe some dirty hack just to get it work.

Avatar
Devlin

Community Member, 344 Posts

9 December 2014 at 10:36pm

I saw your issue on Github. But I cannot confirm this bug. I'm using umlauts everyday and SilverStripe had never a problem with them. I tried your cyrillic string too and it works as expected.

I suggest that you should check your encoding settings in Apache2, in your editor and in your browser.

Avatar
folibis

Community Member, 13 Posts

10 December 2014 at 7:12pm

Edited: 10/12/2014 7:43pm

Hello, @Devlin, thanks for the replay.
I use nginx, not Apache, and it looks than its response in UTF-8. You can see it here - http://ruslan.pw/
Also I tested the page in Firefox, Opera and IE - same result. Certainty, I saved template in UTF-8.
What else settings have I check?

P.S. I didn't updated my SS installation last year. It was 3.0 as I remember. And after I updated to 3.1 before weak or 2 I got to this error.

Avatar
Devlin

Community Member, 344 Posts

10 December 2014 at 10:49pm

Mhm, the html output is certainly unicode... And your cyrillic string in the title tag works well enough.

To confirm your issue, you could inspect your template cache file and compare the cached result with the original template file.

For example:
- you have "тест" in "themes/green2/templates/Page.ss"
- open the file with another editor to confirm that "тест" is still correct!

- Create a "silverstripe-cache" folder in your root directory.
- Reload the website to create cache files in your new "silverstripe-cache" folder
- Go to the "silverstripe-cache/[nginx-user]/" folder
- there should be a file ".cache.themes.green2.templates.Page.ss" (this is PHP code and the cached equivalent of "themes/green2/templates/Page.ss")
- see what is going on in there and check what happend with the rest of your webpage after the string "тест".

Avatar
folibis

Community Member, 13 Posts

10 December 2014 at 11:39pm

Edited: 10/12/2014 11:38pm

Oh, perhaps I was a bit inaccurate in defining the problem. I see wrong text only if it was written directly in template. The rest of the text, even if it contains cyrillic characters is displayed without problems. For example page title displays by $SiteConfig.Title.
I double cheched Page.ss with Notepad++ and also in console (witch uses utf-8) and it undoubtedly encoded in UTF-8.

As you suggested I created silverstripe-cache folder. So after site reloding .cache.themes.green2.templates.Page.ss looks exactly like the HTML page.
All the output after cyrillic word is truncated.
Page.ss

...
<body>
<div>тест</div>
</body>
</html>

.cache.themes.green2.templates.Page.ss

...
$val .= '<body>
<div>тестстт▒';

Avatar
Devlin

Community Member, 344 Posts

11 December 2014 at 1:46am

I see.

Is the site in dev mode? Any chance the error.log says something? Or that preg_last_error() returns something different than 0? I think there were some problems with older PHP versions too.

http://php.net/manual/en/function.preg-last-error.php

"> But how can I solve this problem just now? My site is closed now so I need a temporary solution or advice or maybe some dirty hack just to get it work."

I'm still not sure that this is a SilverStripe issue. But you could downgrade to 3.0, if this worked for you. Or you could refrain from using cyrillic strings directly in the template and write your text as a method. As in:

// Page.php
class Page extends SiteTree{
	function test() {
		return "тест";
	}
}
// Page.ss
<div>$test</div>