Kornel,
Thanks for going to this trouble.

You know, to be fair to PHPTAL... I was having more problem with scope in
PHP than PHPTAL, in hindsight.

WordPress doesn't make it really easy to know in what order things happen
and what scope you're in.

I must have understood your description of tal:define, because I've used it
in just that way... "local" within macros and such. Works a treat :)

Cheers,

-Alister

On Mon, Jan 5, 2009 at 9:29 PM, Kornel Lesiński
<kor...@aardvarkmedia.co.uk>wrote:

> 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, i.e.:
>
> <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
> </div>
> 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
> </div>
>
>
> 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
> </div>
> 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'
>        </div>
>        x is 'global' again
> </div>
>
> 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
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>



-- 
Alister Cameron
Managing Director
Cameron Creative Pty Ltd
www.cameroncreative.com

Creative, Strategic, Innovative... never boring!
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to