You've blamed scoping on a few problems, so let me clarify how scoping works in 
PHPTAL (it's quite simple actually :)

Variables set via $phptal->xxx or $phptal->set('xxx',...) are available 
everywhere in the template.

Variables set in tal:define attribute live only as long as the element is open, 

<div tal:define="x 'something'" tal:condition="x can be used here">
 x works here
        <div tal:define="something else">x works here too - scopes can be nested 
without problems</div>
 x works here
x is no more.

tal:define is evaluated before most other attributes, so you can use defined 
variables in condition, repeat, etc.

You can redefine variables:
<div tal:define="x number:1"> ${x} is 1
        <div tal:define="x number:2"> ${x} is temporarily 2 now </div>
        ${x} is 1 again

Variables that are defined as global in the template behave more like PHP 
variables and ignore nesting of tags:

global x isn't defined yet
<div tal:define="global x '...'">
 x works here
and global x works here too

global variables can be permanently redefined by any tal:define.

local variables can "shadow" global variables:
<div tal:define="global x 'global'">
        <div tal:define="x 'local'">
                x is 'local'
        x is 'global' again

but I suggest that you avoid global variables - it's easy to shoot yourself in the foot with them :) When you need them, it might be sign that you're trying to put too much logic into the template.

regards, Kornel

PHPTAL mailing list

Reply via email to