Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42700

Pass in variable to Mako template

In Perl, by using Template Toolkit, here is what I do

Perl

my $vars = {
    name     => 'Count Edward van Halen',
};

$tt->process('letters/overdrawn', $vars)
    || die $tt->error(), "\n";

HTML

Dear [% name %],

In Mako template, how can I do so? Check through their render function, doesn't get much hint.

Upvotes: 3

Views: 5719

Answers (1)

Novikov
Novikov

Reputation: 4489

Use named arguments

mytemplate.render(myvar1="var1", mydict=dict())

In the mako side you'd do

${myvar1}
% for val in mydict:
    ${val}
% endfor

Upvotes: 7

Related Questions