[cgiapp] Custom template tags
Ron Savage
ron at savage.net.au
Tue Oct 12 19:02:16 EDT 2010
Hi Michael
On Tue, 2010-10-12 at 16:33 -0400, Michael De Soto wrote:
> On Tue, Oct 12, 2010 at 3:32 PM, Michael Peters <mpeters at plusthree.com>wrote:
The other way would be to use a different templating module, with a
different syntax than HTML::Template, which - hopefully - MT would
ignore.
I've switched to Text::Xslate, which uses <: $var_name :>.
I don't use MT.
What's good about Text::Xslate is that you pass in a hashref of options,
which is much more efficient than calling param() once for each option.
See also http://xslate.org/benchmark.html
In cgiapp_prerun() I do:
$self -> param
(
templater =>
Text::Xslate -> new
(
input_layer => '',
path => ${$self -> param('config')}{template_path},
)
);
which gets passed into a viewer as the value of a templater() attribute,
after which I can do:
my($param) =
{
context => $context,
current_page_name => $$page{name},
design_name => $$design{name},
homepage => $$page{homepage} eq 'Yes' ? 'checked' : '',
name => $$page{name},
sid => $self -> session -> id,
site_name => $$site{name},
submit_text => 'Save',
template_name => mark_raw($self -> build_select('asset_types',
$asset{asset_type_id}) ),
};
return $self -> templater -> render('page.tx', $param);
That single call to render() is very nice.
mark_raw() is part of Text::Xslate.
--
Ron Savage
http://savage.net.au/
Ph: 0421 920 622
More information about the cgiapp
mailing list