2

我正在使用带有基本模板的 webpy

render = web.template.render(basedir + 'templates/', base='layout', globals=globals_vars_custom)

layout.html我有类似的东西:

$def with (content)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
    <head>
        <title>PAGE TITLE</title>
        <!-- Some CSS and some javascript -->
    </head>
    <body>
        $:content
    </body>
</html>

这个基本模板适用于我网站的 90%,但我有一个页面,我需要在其中插入一些其他数据<head>(一些元标记)。

我怎样才能做到这一点?如何将<head>可以轻松覆盖的结构放入模板中?

谢谢!

4

1 回答 1

5

这比我说的要容易:

您可以在模板中创建变量:

在 page.html 你可以定义一个变量

$var title = 'specific title'

在基本模板 layout.html 中,您可以调用变量:

$def with (content)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
    <head>
        <title>$content.get("title","DEFAULT TITLE")</title>
        <!-- Some CSS and some javascript -->
    </head>
    <body>
        $:content
    </body>
</html>

我希望这个答案对其他人也有用。

于 2011-01-13T18:46:33.177 回答