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">
                <li tal:repeat="item items">
                        <tal:block metal:define-slot="li" />

<tal:block tal:define="items php:array('a', 'b', 'c')" metal:use-macro="ul">
        <tal:block metal:fill-slot="li">

I would expect the template to be rendered like this:

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

Reply via email to