"calls without an existing one..." rendering in SilverStripe output"calls without an existing one..." rendering in SilverStripe output

Posted November 13th, 2010 in SilverStripe

When moving a SilverStripe site from one server to a differently configured one we came across an odd bug where some content from the SSViewer.php file would render in the output the first time that template was requested but not on subsequent requests.

The content rendered in the browser

The content was rendered before the start of the actual expected HTML (from <!DOCTYPE html> on) and started like this:

calls without an existing one // to avoid confusion when using the include 
in different contexts. // Entities without a namespace are deprecated, but 
widely used. $content = ereg_replace('<' . '% +_t\((\'([^\.\']*)\'|"([^\."]*)")
(([^)]|\)[^ ]|\) +[^% ])*)\) +%' . '>', '

and then some stuff from our template, unparsed.

Why the error occurs

Searching the SS codebase I found the "calls without an existing one" in the sapphire/Core/SSViewer.php file. There's a chunk of code that looks like this:

// $content = "<!-- getTemplateContent() :: identifier: $identifier -->". $content;
// Adds an i18n namespace to all <% _t(...) %> calls without an existing one
// to avoid confusion when using the include in different contexts.
// Entities without a namespace are deprecated, but widely used.

The error occurs because there are SS template placeholders in the form of the <% and %> tags and they somehow get mixed up with what's in the template, despite being in a comment in PHP code.

Note that the error only occurs the first time the particular template is requested and doesn't occur on subsequent requests. It's easily reproducable; if you ?flush the page you'll get the error every time. I'm not sure why it affected this partcular website on one server and not the other.

Versions of SilverStripe affected

This bug affects SilverStripe 2.4.0 and 2.4.1. It has been fixed in 2.4.2

The solution

Either upgrade to the latest version of SilverStripe, or remove the <% and %> from the comment in the sapphire/Core/SSViewer.php file.

Comments

blog comments powered by Disqus