是否可以将可变参数传递给Mako中的include标记?

She*_*ena 10 arguments function mako include

我有一个不止一次包含mako模板B的mako模板A. Mako模板B需要某些参数,我需要在include上将它们设置为不同的值.

在A.mak:

<%include 
    file="/components/B.mak" 
    args="lItems=some_variable, foo='bar'"
    />

<%include 
    file="/components/B.mak" 
    args="lItems=some_other_variable, foo='moooo'"
    />
Run Code Online (Sandbox Code Playgroud)

在B.mak:

<%page args="lItems, foo"/>
%for dItem in lItems:
    etc
Run Code Online (Sandbox Code Playgroud)

这种事情甚至可能吗?我知道如果我将lItems设置为'some_value'和'some_other_value'(即:直接编码到A.mak中的字符串),它会工作但是我想用some_variable = [some,craze,list]和渲染A.mak some_other_variable = [some,other,craze,list].

上面的代码给出了错误:

File ".../mako/runtime.py", line 202, in __str__
    raise NameError("Undefined")
NameError: Undefined
Run Code Online (Sandbox Code Playgroud)

我也试过像这样做包括:

 <%include 
    file="/components/B.mak" 
    args="lItems=${some_other_variable}, foo='moooo'"
    />
Run Code Online (Sandbox Code Playgroud)

但那是语法错误......

我也尝试使用def:

${the_B_def(foo='bar',lItems=some_variable)}
Run Code Online (Sandbox Code Playgroud)

并得到了NameError: Undefined.

所以我的问题是:如何将变量传递给模板中的模板?

Rég*_* B. 7

你几乎在那里:

在A.mak:

<%include 
    file="/components/B.mak" 
    args="lItems=some_other_variable, foo='moooo'"
    />
Run Code Online (Sandbox Code Playgroud)

在B.mak:

<%page args="lItems, foo"/>
%for dItem in lItems:
    ${foo}
%endfor
Run Code Online (Sandbox Code Playgroud)