Compiled templates render like interpreted ones: what to check when you upgrade
Templates can run interpreted or compiled ([TemplateSettings] TemplateCompile). The two modes are meant to give the
same output; in a few places the compiled code did not. Each section below names one place that now follows the
interpreter, who can notice, and what to check.
{default} and {let} keep a variable passed as null
What changed. A variable that exists with the value null counts as existing in compiled templates, as it
always did in interpreted ones. {default} no longer replaces it with its fallback and no longer removes it at the
end tag; {let} does not overwrite it (the interpreter also writes a warning that the variable already exists; the
compiled code does not). A variable that does not exist is still defined and removed at the end tag. The same holds
for {include} and {tool_bar}: a variable of the caller that holds null and is overwritten by a parameter of the
include is given back as null afterwards, where the compiled code removed it.
Who is affected. Templates that rely on {default var=fallback} supplying the fallback when the caller passes
null explicitly, with compilation enabled. They saw the fallback before; they now see null, which is what the same
template showed with compilation off.
What to do. Test for null where the fallback is wanted, for example {if is_null( $var )}…{/if} or
$var|choose( … ). Compilation off needs no change.
Compiled fetch_alias with a parameter variable applies the alias's constants
What changed. {fetch_alias( 'alias', $params )} with the whole parameter hash in a variable now passes the
Constant[] values of fetchalias.ini in compiled templates, as interpreted templates always did. A key present in
$params decides (a null value gives the parameter's default); a key that is missing takes the constant. Before, the
compiled code ignored the constants and used the parameter's default.
Who is affected. Templates that call an alias this way and relied on the compiled result, for example a class filter constant that was silently not applied, so the fetch returned more objects than the same template with compilation off.
What to do. Check the pages that fetch through such aliases: the result now equals the interpreted one. To keep a
value the alias defines as a constant, pass the key in $params explicitly. Compilation off needs no change.
The same rules now apply when the parameters are written in the template (hash( ... )): a constant is looked up by
the function's own parameter name, also for a parameter the alias renames with Parameter[]; it wins over a value
given under the renamed name, and only a value under the function's own name overrides it. A constant that names an
empty list (Constant[class_filter_array]=) counts as no constant, so the parameter's default applies, as in
interpreted templates.
A compiled include survives a template cache clear
What changed. A compiled template that includes another template by a fixed URI ({include uri="design:…"})
now renders the included template when that template's compiled file disappears while the page renders, for example
because the template cache is cleared at that moment. The generated code checks the result of the include and, if
the file could not be opened, renders the template through eZTemplate::processURI(), which compiles it again.
Before, the include rendered nothing and the page lost that part. PHP still reports the failed include itself as a
warning; the include of an object forwarder keeps its plain form.
Who is affected. Sites that clear the template cache while the site is serving requests. They no longer see pages with a missing part, and the warning of the failed include is the only message left.
What to do. Nothing. If you watch the PHP or debug log during cache clears, expect the single warning of the failed include and no further errors from the page.
Every template is compiled once after the update
What changed. The code date of the template compiler (eZTemplateCompiler::CODE_DATE) is now part of the name of
every compiled template, and it was raised with the compiler fixes above. A compiled file written by an older compiler
has another name, so it is never found and never run: each template is compiled once more on its first use after the
update. eZTemplateCompiler::compilationFilename() takes the code date as an optional third parameter, which
defaults to the current one; existing callers need no change.
Who is affected. Every installation that compiles templates. The first request that uses a template after the update compiles it again, so the first requests are slower. Compiled files of the older compiler stay on disk, unused, until the next template cache clear.
What to do. Nothing is required. To remove the old files, clear the template cache after the update. Code that
builds the name of a compiled file itself should call compilationFilename() instead of repeating its rules.