[Maypole] additional_data and template_args
Dave Howorth
dhoworth@mrc-lmb.cam.ac.uk
Tue, 04 Jan 2005 11:07:28 +0000
Hi Peter
> Still really the same problem though. You need to put that in every template
> you want menu data or put it in a template that it is included in every
> template. It'd be something like:
> [% IF objects.size == 1; obj = objects.0;
> ELSE; USE obj = Class("$classmetadata.name");
> END;
> menu = obj.menu_data;
> %]
>
> Truth is though, i have a single wrapper I use all my pages within so I only
> need to put that in there and that's a fine solution for now. But i'd much
> rather just put it in additional_data once and be done with it. Aslo, maybe
> someone else's templating system isn't as cool as TT and they don't have
> wrappers or includes. It may be a problem.
Ah, OK, I see a little more clearly what you're saying. In that case
just delay calling menu_data. Take your additional_data code and make it
into a method of the request class:
sub get_menu_data {
my $r = shift;
# get object menu if we have only one object:
if (@{$r->objects} eq 1) {
$r=>objects->[0]->menu_data;
}
# else class menu
else {
$r->model_class->menu_data;
}
}
Then in your template you write [% menu = request.get_menu_data %]
I hope :)
Cheers, Dave