Mako テンプレートで CherryPy を使用しています。最初の呼び出しから引数を渡す方法を考え出そうとしています (この例ではtitle):
class Landing(object):
def index(self):
tmpl = lookup.get_template("index.html")
return tmpl.render(title="Hello World")
index.exposed = True
にindex.html:
<%inherit file="base.html"/>
<%def name="title()">$(title)</%def>
this is the body content
次に、継承されたbase.htmlテンプレートに:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>$(self.title())</title>
</head>
<body>
<h1>$(parent.title())</h1>
${self.body()}
</body>
</html>
私は試してみましたがself.title、parent.titleどちらも機能しません。最初の呼び出しから変数を渡すにはどうすればよいですか?