in reply to An Idea for a New Template Toolkit Improvement(?)
now for the template codesub ContextString { my $context = shift(); if($context eq "foo") { return "String 1"; } elsif($context eq "bar") { return "String 2"; } } my $t_vars = { context_sub => \&ContextString, other => "mmm donuts", }; # config opts are whatever you need them to be my $template = Template->new($config_opts); $template->process("template_file.tt",$t_vars) || die $template->error();
in this case the template would be. . . [% context = "bar" %] [% IF context %] Message: [% context_sub(context) %] [% END %] . . .
Message: String 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: An Idea for a New Template Toolkit Improvement(?)
by monsieur_champs (Curate) on Mar 30, 2004 at 20:42 UTC | |
by amw1 (Friar) on Mar 30, 2004 at 21:00 UTC | |
by Ovid (Cardinal) on Mar 30, 2004 at 23:22 UTC | |
by clscott (Friar) on Mar 30, 2004 at 20:57 UTC | |
by Hofmator (Curate) on Mar 31, 2004 at 08:38 UTC |