mako テンプレート B を複数回含む mako テンプレート A があります。Mako テンプレート B は特定の引数を想定しており、インクルード時にそれらを異なる値に設定する必要があります。
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'"
/>
B.mak では:
<%page args="lItems, foo"/>
%for dItem in lItems:
etc
この種のことは可能ですか?lItems を 'some_value' および 'some_other_value' (つまり、A.mak に直接コード化された文字列) に設定すると機能することはわかっていますが、 and を使用して A.mak をレンダリングしたいと考えていsome_variable = [some,craze,list]
ますsome_other_variable = [some,other,craze,list]
。
上記のコードは私にエラーを与えます:
File ".../mako/runtime.py", line 202, in __str__
raise NameError("Undefined")
NameError: Undefined
私も次のようにインクルードを試みました:
<%include
file="/components/B.mak"
args="lItems=${some_other_variable}, foo='moooo'"
/>
しかし、それは構文エラーです...
私もdefを使って試しました:
${the_B_def(foo='bar',lItems=some_variable)}
そして得NameError: Undefined
た。
私の質問は次のとおりです: テンプレート内のテンプレートに変数を渡すにはどうすればよいですか?