Hi,

when you fill a slot in phptal, it bubbels into all existing contexts:

public function fillSlot($key, $content)
{
     $this->_slots[$key] = $content;
     if ($this->_parentContext) {
          // setting slots in any context (probably violates TAL, but works 
around bug with tal:define popping context after fillslot)
          $this->_parentContext->fillSlot($key, $content);
     }
}

This breaks your rendering, if you reuse a macro somewhere within it's own slot.
I'll try to give you an example (although it is kind of tricky):

box.html:
<tal:block metal:define-macro="box">
    <div class="box">
        <div class="box-heading"><tal:block metal:define-slot="box-heading" 
/></div>
        <tal:block metal:define-slot="box-content" />
    </div>
</tal:block>

some-page.html:
<tal:block metal:use-macro="box">
    <tal:block metal:fill-slot="box-heading">This are two news</tal:block>
    <tal:block metal:fill-slot="box-content">
        <tal:block metal:use-macro="box">
            <tal:block metal:fill-slot="box-heading">First news</tal:block>
            <tal:block metal:fill-slot="box-content">Lorem ipsum...</tal:block>
        </tal:block>
        <tal:block metal:use-macro="box">
            <tal:block metal:fill-slot="box-heading">Second news</tal:block>
            <tal:block metal:fill-slot="box-content">Some more lorem 
ipsum...</tal:block>
        </tal:block>
    </tal:block>
</tal:block>

Rendering this I would expect this output:

<div class="box">
    <div class="box-heading">This are two news</div>
    <div class="box-content">
        <div class="box>
                <div class="box-heading>First news</div>
                <div class="box-content">Lorem ipsum</div>
        </div>
        <div class="box>
            <div class="box-heading>Second news</div>
            <div class="box-content">Some more lorem ipsum...</div>
        </div>
    <div>
</div>

But because the slot is set in any context, the last "box-heading" slot 
overwrites the one from the parent context:

<div class="box">
    <div class="box-heading">Second news</div>
    <div class="box-content">
        <div class="box>
                <div class="box-heading>First news</div>
                <div class="box-content">Lorem ipsum</div>
        </div>
        <div class="box>
            <div class="box-heading>Second news</div>
            <div class="box-content">Some more lorem ipsum...</div>
        </div>
    <div>
</div>

I think this is broken. Of course, it is not possible to come up with an 
example that does make advantage of this behavior.

Could somebody explain what the comment "works around a bug with tal:define" 
means?

Cheers,
Per

P.S.: My suggested patch is of course to strip the last four lines of the 
method... I am currently using a version patched like this and it works without 
any hassle...

--

webfactory GmbH
Per Bernhardt, Anwendungsentwickler

Lessingstraße 60
53113 Bonn
Germany

Fon +49 228 9114455
Fax +49 228 9114499
www.webfactory.de
p...@webfactory.de

Geschäftsführer: Sebastian Kugler, Matthias Pigulla
Handelsregister: HRB 8673, Amtsgericht Bonn
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to