简体   繁体   中英

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.

Use named arguments

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

In the mako side you'd do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM