webpy:如何覆盖基本模板的内容?

发布于 2024-10-10 18:38:55 字数 698 浏览 0 评论 0原文

我在 layout.html 中使用带有基本模板的 webpy

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

我有类似的内容:

$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%,但我有一个页面需要在其中插入一些内容 内的其他数据(一些元标记)。

我该怎么做?如何将 放入可以在模板内轻松覆盖的结构中?

谢谢!

I'm using webpy with a basic template

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

in layout.html I have something like:

$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>

This basic template works fine for the 90% of my site, but I have a page in which I need to insert some other data inside the <head> (some meta tags).

How can I do this? How can I put the <head> inside a structure that I can easily override inside a template?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-10-17 18:38:55

这比我想象的要容易:

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

定义一个变量,

$var title = 'specific title'

在 page.html 中,您可以在基本模板 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>

您可以调用该变量:我希望这个答案对其他人也有用。

It was easier than I tought:

You can create a variable in a template:

in page.html you can define a variable

$var title = 'specific title'

in the base template layout.html you can call the varable:

$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>

I hope this answer can be useful also for other people.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文