Hi [EMAIL PROTECTED],
I have the following problem:
I'm writing a CMS and I got a problem with this CMS and the
HTML::Template. Imagine the following template:
...
<body>
menu1
<table>
menu2
menu3
</table>
</body>
</html>
My idea is, that you can program the logic of the website (menu
structure, links, SQL...) in a Package and combine this with a
template. The old way is like this:
<body>
<TMPL_VAR NAME=menu1>
<table>
<TMPL_VAR NAME=menu2>
<TMPL_VAR NAME=menu3>
</table>
</body>
</html>
The code is like this:
# open the html template
my $template = HTML::Template->new(...);
# fill in some parameters
$template->param(MENUE1 => ...doing... );
$template->param(MENUE2 => ...doing... );
$template->param(MENUE3 => ...doing... );
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
If you remove the "<TMPL_VAR NAME=menu1>" from the above template (the
editor and the programmer are not the same person) you get the error
message. You can turn off the error message with "die_on_bad_params =>
0", but:
- The "menu1" is still created but not used, this may be bad for speed.
- The way is not OO.
I have extended HTML::Template the following way:
<body>
<TMPL_OO NAME=menu1>
<table>
<TMPL_OO NAME=menu2>
<TMPL_OO NAME=menu3>
</table>
</body>
</html>
package FooBar;
[...]
sub print
{
my ($self) = @_;
# open the html template
my $template = HTML::Template->new(...);
# Telling the Template about my object.
# Yeah, I know the name of the subroutine is a bad choice. B-)
my $template->oo($self);
# No need to fill in the parameter.
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
}
sub menu1
{
my ($self) = shift;
return "...menue1...";
}
sub menu2
{
my ($self) = shift;
return "...menue1...";
}
sub menu3
{
my ($self) = shift;
return "...menue1...";
}
And everything is fine. The Menu1 are only created if the appear in the
template.
The "diff -ur" patch is about 97 lines long and it's done in
'HTML::Template'ish way with an HTML::Template::OO object.
Is somebody interessested in the patch or is this stuff too foobar?
What do *you* think?
P.S: I know you can do this behavior with disclosures and CODE
references...
--
So long... Fuzz
-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users