[ZPT] Macro expansion and slots

Evan Simpson evan@4-am.com
Tue, 18 Feb 2003 12:30:32 -0600


Clemens Robbenhaar wrote:
>  When I check the "Expand macros when editing" I get the macros all
> expanded, as indended. If I uncheck this box, the macro expansions is
> gone, but only if I haven't saved the page template. If I save the page
> template in between, I can uncheck the "Expand macros when editing" and
> still get the marcos expanded. (I am quite sure my edits did not destroy
> the macro reference; if I edit code which is actually in the macro and
> not in the template, this modification is not rendered when I view the
> page.)

This is a long-standing issue.  When you save a template, the text is 
stored unchanged, and a TAL "program" is generated.  In order to 
collapse macros, we would either need to run a separate parse/generate 
process on the text in order to identify and snip out macro text, or we 
would need to give the TAL "program" the ability to generate a collapsed 
version of the template.  Neither of these is trivial (although the 
first isn't *too* hard) so nobody has tackled them.

>  Hm, maybe this is a feature? When editing code which is actually
> contained in the macro and not in the page template, do not collapse
> marcos, for these modification do not get lost? 

In a very weak sense, yes, this is a feature.  Technically, you can 
write <div metal:use-macro="here/foo.zpt/macros/page | default"> and get 
the last-saved expansion of the macro if the attempt to resolve 
"here/foo.zpt/macros/page" failed at runtime for some reason.

In practice, though, this is terribly fragile, since an edit-time 
failure to resolve the macro will quietly drop the whole use-macro 
attribute during expansion :-(

Cheers,

Evan @ 4-am