[Zope] Re: METAL question: relative reference to a macro defined in the same file

Tonico Strasser contact_tonico at yahoo.de
Fri Apr 9 08:51:33 EDT 2004


Johan Carlsson wrote:

> Tonico Strasser wrote:
> 
>> Johan Carlsson wrote:
>> I still do not understand why you want to move your presentation 
>> templates around. If your template is in a folder at the root of your 
>> site, let's say 'templates', you wouldn't need to change the path from 
>> other templates referring to it when you move them.
> 
> 
> Well, first the template is in a skin and second I know by experience 
> things may change (for anyway , like renaming or moving things around, 
> maybe reusing the template by coping it and change it in
> another location.
> 
> you can compare it to using absolute URLs or relative URLs in a
> collection of HTML pages. Using relative references you can move
> the collection without breaking the internal references.
> This is quite useful, for instance if you distribute the collection
> and you can't know on for hand where the user will unpack it.
> 
> What I want is the same functionality in TAL and METAL.
> You have the "template" reference that points on the calling template,
> why not have a "current_template" (or something) that points the 
> template that the code is being executed.
> 
> The reason I want this is because I was working on a template and
> found my self in the situation that the code was becoming more and
> more complicated and it was hard to have an overview.
> So I factored out one part that was occuring in several places,
> making the "code" much more readable. I put the out-factored part
> in a macro definition in the same file, but to use it I was required
> to enter the complete path to the template (e.g. 
> "here/skin_path/current_temp/macros/macro_name"), what I would like
> to do is "current/macros/macro_name", because the macro is local.

Hm. This only happens if you want to access a macro that is not in the 
current template but in a macro of another template used for render the 
current template. (Does this make sense?)

If the macro were in the current template you would be able to access it 
with 'template/macros/your_macro'.

I would simply create a folder called 'templates' (if you use 
portal_skins you'll don't need this) and create a template inside called 
'my_macros' and use the macros from this template.

With a 'templates' folder in the site root it would look like:

   metal:use-macro='here/templates/my_macros/macros/needful_thing'

Even simpler with CMF skins tool:

   metal:use-macro='here/my_macros/macros/needful_thing'

Does this work for you?

Tonico




More information about the Zope mailing list