[ZPT] Question on using metal-slots for menus

Fernando Martins fmartins at hetnet.nl
Sat Jul 5 00:57:03 EDT 2003


Charlie Clark wrote:
...
> I have just started working with METAL but have so far been
> unable to work out the best way of having
> context-based menus. My website's content is essentially static
> with a lot of RDBMS calls (through ZPT)
> so I think I should be okay with a single page_macro and slots.
> What I'm struggling with is sub-menus.

FWIW, it seems you want a sub-templating system, i.e., two levels of macros:

/master_page
/search/sub_master_page
/search/index_html
/register/sub_master_page
/register/index_html
...

/master_page:
<html metal:define-macro="page">
<head></head>
<body>
<a href="/search">Search</a><br>
<a href="/register">Register</a><br>
<a href="/about">About</a><br>
<div metal:define-slot="sub_menu">sub menu options</div>
<div metal:define-slot="content">Welcome to my website</div>
</body>
</html>


/search/sub_master_page:
<metal:block define-macro="sub_page"
<html metal:use-macro="master_page/macros/page">
<head></head>
<body>
<p metal:fill-slot="sub_menu">
	Normal search<br>
 	Advanced search<br>
</p>
<div metal:fill-slot="content" metal:define-slot="middle_man">
Welcome to my website
</div>
</body>
</html>
</metal:block>


/search/index_html:
<html metal:use-macro="here/sub_master_page/macros/sub_page">
<head></head>
<body>
<p metal:fill-slot="middle_man">
Welcome to my website<br>
Here Comes the Real content
</p>
</body>
</html>


The trick here is to visualise text being replaced in the right order.

<div metal:fill-slot="content" metal:define-slot="middle_man">

Your index_html page fills in middle_man and sub_master_page in turn fills
in content. Note that middle_man could be named content; you don't need a
different name.

I don't know about performance in real life. It's also a bit clumsy because
you have to carry reduntant HTML around if you want to benefit from an HTML
visual editor. It also looks complex if you only have a simple sub-menu
system.

Another alternative, would be to have a secondary master page, just with a
collection of macros (a macro for each sub-menu) and your index_html, etc.
pages, would be

<html metal:use-macro="here/master_page/macros/page">
<head></head>
<body>
<div metal:fill-slot="sub_menu" tal:omit-tag="">
<span metal:use-macro="here/second_master/macros/search_menu"></span>
</div>
<p metal:fill-slot="content">
Welcome to my website<br>
Here Comes the Real content
</p>
</body>
</html>

HTH,
Fernando




More information about the ZPT mailing list