Pass variable to Mako template

In Perl, using the Template Toolkit, this 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 the Mako template, how can I do this? Test your function renderwithout getting a big hint.

+3
source share
1 answer

Use named arguments

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

On the mako side you do

${myvar1}
% for val in mydict:
    ${val}
% endfor
+6
source

Source: https://habr.com/ru/post/1774442/


All Articles