Kornel Lesiński wrote:
I've meant using callback (macro called from macro) instead of slots.

e.g. your code modified to use callbacks:

<html   metal:define-macro="main"  tal:define="people php:peopleGet()">
<head>
</head>
<body>

<div metal:use-macro="${callback}" tal:comment="will call any macro named in callback variable">
</div>

</body>
</html>


<html metal:use-macro="person.zpt/main" tal:define="callback string:myfile.zpt/content_main" tal:comment="variable tells main macro to call content_main below"><head>
</head>
<body>
<div metal:define-macro="content_main">
<ul>
<li tal:repeat="user people" tal:content="user/name"></li>
</ul>
</div>
</body>
</html>

ok, thanks, I get it but I find the architecture I have more intuitive/simpler.
If you have certain variables on all pages, why not simply set them from PHP?

I don't know what this means. putting it in a session variable??
In PHPTAL slots are executed in context where fill-slot is used, not in context where define-slot is, so what you're trying to achieve is not possible with slots.

I wasn't aware that in Zope context is different. Can Zope's fill-slot use variables from both its context and the macro? If both macro and context of fill-slot have variable with same name, which one "wins"?

I'm not sure what you mean by fill-slot context. If I have macro.zpt and page.zpt, the html tree that defines the context of variables is the one of page.zpt. When a use-macro appears, it is inserted and then all variables of the macro take effect. So, when it arrives to the fill-slot, the context is the combination of variables from page.zpt and then from macro.zpt. Therefore, within a fill-slot, the variable that wins (visible) is merely the one closest to the use of the variable.

A small but important detail is that any tal statement in the define-slot is ignored. That is, any tal in the fill-slot takes over. This is valid for any attribute actually. Those in define-slot are ignored.

In my use case, since the macro starts in <html>, in practice the (initial) scope of page.zpt does not exist until a fill-slot takes place.


Regards,
Fernando

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

Reply via email to