[PHPTAL] Best way to execute different templates in the same
context?
Laurent Bedubourg
laurent at motion-twin.com
Mon Apr 2 17:59:49 CEST 2007
On Mon, 02 Apr 2007 16:15:35 +0100
"Kornel Lesinski" <kornel at aardvarkmedia.co.uk> wrote:
>
> In application I'm working on pages are created in two phases (and I
> can't change that):
> 1. main content of the page is prepared and stored as HTML
> 2. later this content is used in another template that adds rest of
> the HTML
>
> If I just execute them on separate instances of PHPTAL, I can't
> share global variables and macros (filled slots) between the two.
>
> I've tried to hack PHPTAL to allow that by copying $tpl->_context
> and $tpl->_globalContext to new instance, but it doesn't work -
> $tpl->_context->_slots doesn't contain slots filled in previous
> template.
Hi Kornel,
Yes, slots are cleaned up after macro call (to avoid name collision).
Maybe you can store these slots using a PHPTAL trigger (see manual), the idea would be to call your "save slots" trigger once slots are filled.
I am not sure it will work out of the box but it should, providing you are able to access template slots.
Simplier, you can also try to call a php function at the end of your macro call
<div metal:use-macro="...">
<div metal:fill-slot="dummy">bla bla bla</div>
<?php store_slots($ctx); ?>
</div>
You can use $ctx->getSlot('slotName') to get a slot content.
$ctx->_slots is private but you can hack a little to use it...
Regards
Laurent
--
Laurent Bedubourg
lbedubourg at motion-twin.com
http://www.motion-twin.com
More information about the PHPTAL
mailing list