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:
http://phptal.org/manual/en/split/metal-use-macro.html#macro-callback

See also:
http://www.mail-archive.com/phptal@lists.motion-twin.com/msg01331.html

--
regards, Kornel

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to