[Koha-patches] [PATCH] Bug #2756 opacbookbag preference turns off add items to list

Joe Atzberger joe.atzberger at liblime.com
Thu Nov 6 16:42:36 CET 2008


On Thu, Nov 6, 2008 at 9:50 AM, Allen Reinmeyer <allen.reinmeyer at liblime.com
> wrote:

>   <script type="text/javascript" language="javascript"
> -<!-- TMPL_IF NAME="opacbookbag" -->src="<!-- TMPL_VAR NAME="themelang"
> -->/js/basket.js"><!-- TMPL_ELSE -->>var readCookie;<!-- /TMPL_IF
> --></script>
> +<!-- TMPL_IF EXPR="opacbookbag || virtualshelves" -->src="<!-- TMPL_VAR
> NAME="themelang" -->/js/basket.js"><!-- TMPL_ELSE -->var readCookie;<!--
> /TMPL_IF --></script>


This construction (TMPL_IF EXPR) needs to be avoided even if it means extra
lines in the template.  The logic is not what you'd expect because
HTML::Template::Pro takes only a single pass to compile/execute.  In perl,
if you had:
if ($opacbookbag || $virtualshelves) { ... }

That would be fine with one or both of the variables undefined.  But in
H:T:P, whatever goes into EXPR must always be defined at the beginning of
execution (and not at runtime, nor populated inside a LOOP).  In this case,
that means the EXPR will give an error when either variable is unpopulated,
so despite appearances the behavior is NOT equivalent to:
<TMPL_IF NAME="opacbookbag">some_code
<TMPL_ELSIF NAME="virtualshelves>some_code
<TMPL_ELSE>other_code...

There is also no way to avoid this requirement (by putting EXPR inside a
conditional, for example), again because the timing of the evaluation of the
EXPR is *before* the evaluation of TMPL_IF.

A quick grep of one smaller single-branch client's OPAC error log shows *
9435* errors like:
[Thu Nov 06 14:37:51 2008] [error] [client 65.55.209.XX] EXPR:at pos 6:
non-initialized variable branch
[Thu Nov 06 14:37:51 2008] [error] [client 65.55.209.XX] EXPR:at pos 8:
non-initialized variable itemtype

That's going to happen every time a page is loaded and the data doesn't fill
every last EXPR in the template and its INCLuded files.  And obviously, in
practice that is happening a lot.  In short, EXPR is evil.  It offers the
appearance of functionality, and not the real thing.  Do not be tempted by
it's perlish guise.

--Joe Atzberger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-patches/attachments/20081106/2ac2ef1f/attachment-0002.htm>


More information about the Koha-patches mailing list