2013-07-08 6 views
8

mako 템플릿 B가 두 번 이상 포함되어 있습니다. Mako 템플릿 B는 특정 인수를 기대하며 include에 다른 값을 설정해야합니다. A.mak에서Mako의 include 태그에 가변 인수를 전달할 수 있습니까?

: B.mak에서

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

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

:

<%page args="lItems, foo"/> 
%for dItem in lItems: 
    etc 

는 이런 종류의 물건도 가능합니까? lItems를 'some_value'와 'some_other_value'(즉 : A.mak에 직접 코딩 된 문자열)로 설정하면 some_variable = [some,craze,list]some_other_variable = [some,other,craze,list]으로 A.mak를 렌더링하고 싶습니다.

위의 코드는 나에게 오류가 있습니다 : 나는 그것을 시도하지만 구문 오류입니다

<%include 
    file="/components/B.mak" 
    args="lItems=${some_other_variable}, foo='moooo'" 
    /> 

...

:

File ".../mako/runtime.py", line 202, in __str__ 
    raise NameError("Undefined") 
NameError: Undefined 

나는 또한 이렇게 같이 포함하고 시도를 def 사용 :

${the_B_def(foo='bar',lItems=some_variable)} 

이고 NameError: Undefined이 있습니다.

내 질문은 : 템플릿 내에서 변수를 어떻게 전달할 수 있습니까?

답변

4

당신 거의 있었다 : A.mak에서

:

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

B.mak에서 :

<%page args="lItems, foo"/> 
%for dItem in lItems: 
    ${foo} 
%endfor 
+0

문서는 예를 들어 있습니다 http://docs.makotemplates.org /en/latest/syntax.html#include – Javier