2012-11-29 5 views
0

다음과 같은 base.html 파일이 있습니다.이 파일은 상속하는 다른 모든 파일의 주 골격 역할을합니다. HTML 파일이 lookup.get_template('foo.html')와 파이썬 파일에서 호출됩니다상속 된 파일의 액세스 특성

<%inherit file="base.html" />              

Whatever... ${anotherAttribute} 

:

<%! import cherrypy %>       
<!DOCTYPE html>        
<html>                    
    <body>           
    <div class="container"> 
     <% attribute='defaultValue' %> 
     ${attribute} 
     <p>         
       ${self.body()}     
     </p>         
    </div>          
    </body>          
</html> 

는 지금은 이름을에게 foo.html을 할 수는 base.html 상속 다른 파일이 있습니다.

anotherAttributelookup.get_template('foo.html').render(anotherAttribute='bar')으로 액세스 할 수 있습니다. 이제 attributebase.html에 액세스하는 방법이 궁금합니다.

답변

0
당신이 "ATTR"와 모듈의 범위를 통해 같은 단지 주 속성 수

:

base.html

<%! 
attribute = 'defaultvalue' 
%> 

foo.html 파일이

${self.attr.attribute} 

그렇지 않으면 base.html가 필요 foo에 직접 전달 :

base.html

<% 
    attribute = 'defaultvalue' 
%> 

${self.body(attribute=attribute)} 

foo.html을

<%page args="attribute"/> 

${attribute}