On Thu, Oct 25, 2001 at 12:52:50PM -0700, Bill Moseley wrote:
> Just to save me some time, are there any examples of building sidebar
> menus?
A simple way to start is to add a META directive to each source page
indicating which section it belongs to. e.g.
src/hello.html:
[% META
title = 'My Interesting Document'
section = 'foo'
%]
....
src/goodbye.html:
[% META
title = 'Another Interesting Document'
section = 'bar'
%]
....
You then define a PRE_PROCESS or PROCESS option to add a menu to each
page. For example, in your ttree config file:
src = ~/websrc/example/src
lib = ~/websrc/example/lib
dest = ~/websrc/example/html
pre_process = config
process = layout
Your config file might look like this:
lib/config:
[% section = {
foo = 'The Foo Section'
bar = 'The Bar Section'
...
}
menu = [ 'foo', 'bar', ... ]
%]
your layout file might look like this:
lib/layout:
[% WRAPPER html/page;
PROCESS menu;
PROCESS $template;
END
%]
and your menu file might look something like this:
lib/menu:
[% FOREACH item = menu;
IF item == template.section;
INCLUDE button/active
href = "$root/$item/index.html"
text = section.$item;
ELSE;
INCLUDE button/inactive
href = "$root/$item/index.html"
text = section.$item;
END;
END
%]
That's the basic idea: use template.metadata to define things like section
identifiers which you can then reference in your shared menu component.
Another way to approach it is to define all your metadata somewhere else
(e.g. in a TT config file, XML file, SQL database, etc) and then use
template.name to build the menu. For example, you might have source files:
foo/hello.html
bar/goodbye.html
and then use something like:
[% template.name.split('/').0 %]
to get the 'foo' or 'bar' element which gives you the section id.
Or you might have some black-box magic like this:
[% USE docset('/path/to/my/docset/config.xml') %]
[% metadata = docset.document(template.name).metadata %]
[% section = metadata.section %]
There are, of course, many ways to do it. :-)
> I will define a standard menu of first-level pages, but when those pages
> are visited have a sub-menu displayed for that page. The small twist would
> be that I'd like to be able to automatically generate that sub-menu from,
> say, <h2> tags within that page (so people that don't know TT at all could
> still work with the content).
Interesting idea.
You could write your main layout template like this:
[% WRAPPER html/page;
content = PROCESS $template FILTER my_submenu_filter;
PROCESS menu;
content;
END
%]
Your 'my_submenu_filter' could search through the output generated by
PROCESSing the main $template and build a menu structure from the
<h1>...<h1>, <h2>...</h2> elements, and so on. You could stuff this
info in [% global.submenu %] and then access it from the menu component,
doing something like this:
[% INCLUDE button/inactive FOREACH global.submenu %]
Apologies for the long answer sparse on detail, but hopefully that'll give
you some starting points to work from. Shout if you need more info.
A