We already thought of this solution. Our team agreed that this is not really 
the "PHPTAL"-way and we should use slots.
But now, with your explanation of the technical issue regarding variable scope 
and the added explanation in the manual, it's fine :)

Thank you!

-----Ursprüngliche Nachricht-----
Von: phptal-boun...@lists.motion-twin.com 
[mailto:phptal-boun...@lists.motion-twin.com] Im Auftrag von Kornel Lesinski
Gesendet: Freitag, 25. Juni 2010 12:07
An: Template Attribute Language for PHP
Betreff: Re: [PHPTAL] Variables not found while filling slot

On 24-06-2010 at 18:55:31 Per Bernhardt <p...@webfactory.de> wrote:

> taken the following macro and macro-usage:
> <tal:block metal:define-macro="ul">
>       <ul>
>               <li tal:repeat="item items">
>                       <tal:block metal:define-slot="li" />
>               </li>
>       </ul>
> </tal:block>
> <tal:block tal:define="items php:array('a', 'b', 'c')"  
> metal:use-macro="ul">
>       <tal:block metal:fill-slot="li">
>               ${item}
>       </tal:block>
> </tal:block>
> I would expect the template to be rendered like this:
> <ul>
>       <li>a</li>
>       <li>b</li>
>       <li>c</li>
> </ul>
> But with the current stable and beta what you get is a 
> PHPTAL_VariableNotFoundException saying "Unable to find variable 'item'
> in current scope.
> More generally spoken: Variables defined within a macro definition 
> cannot be accessed while using the macro and filling one of its slots.
> Is this a bug, missing implementation or an unwanted feature?

That's just how it works. Slots work by assigning generated HTML to a hidden 
variable. They're executed immediately when fill-slot is called.

Technically the issue is which scope (variables) slot should "see":

<div tal:define="x '1'" metal:fill-slot="slot">${x}</div>

<div tal:define="x '2'" metal:define-slot="slot"><!-- 1 or 2? --></div>

For slots the answer is 1. Analogous code with macro callbacks would give 2.

I've added explanation to the manual:

See also:

regards, Kornel

PHPTAL mailing list

PHPTAL mailing list

Reply via email to