简体   繁体   中英

Pass variable from called Mako template to inherited template

I am using CherryPy with Mako templates. I am trying to work out how to pass aruguments from the initial call (in this example title ):

class Landing(object):
    def index(self):
        tmpl = lookup.get_template("index.html")
        return tmpl.render(title="Hello World")
    index.exposed = True

to index.html :

<%inherit file="base.html"/>
<%def name="title()">$(title)</%def>
this is the body content

and then to the inherited base.html template:

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>$(self.title())</title>
    </head>
    <body>
        <h1>$(parent.title())</h1>
        ${self.body()}
    </body>
</html>

I've tried self.title and parent.title and neither work. How does I pass the variable from the initial call?

为了使用呈现的变量-您可以将它们与${ title }而非$( title )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM