在turbogears / genshi中阻止标签(py:match)?

发布于 2024-12-25 06:56:49 字数 498 浏览 1 评论 0原文

好吧,我来自 Django,所以如果我写的没有意义,请原谅。我正在尝试使用 genshi “覆盖”涡轮齿轮中我的主模板的一部分。到目前为止,我只尝试了 py:match 指令,但没有成功:

master template:

<div id="menu">
    <div class="menu-items" py:match="topmenu" py:attrs="select('@*')">
        ${select('*')}
    </div>
</div>

child template:

<topmenu> <span> HELLO! </span> </topmenu>

This renders ;你好! 位于菜单 div 之外。我做错了什么?

Ok, I'm coming from Django, so please excuse me if what I write doesn't make sense. I'm trying to "override" a portion of my master template in turbogears using genshi. So far I've only tried the py:match directive with no success:

master template:

<div id="menu">
    <div class="menu-items" py:match="topmenu" py:attrs="select('@*')">
        ${select('*')}
    </div>
</div>

child template:

<topmenu> <span> HELLO! </span> </topmenu>

This renders <span> HELLO! </span> outside of the menu div. What am I doing wrong?

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

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

发布评论

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

评论(1

人心善变 2025-01-01 06:56:49

Genshi py:match 有点难以理解。 给定一个 XPath 表达式,它会查找并替换模板中与该表达式匹配的每个元素 - 包含 py:match 的元素的内容。”

TurboGears2 文档很好地解释了这个概念: “ 意味着实际上具有 py:match 的元素替换了没有它的元素。因此,如果您想将子模板中的菜单放入主模板中,您应该反转两者:

MASTER:

<body py:match="body" py:attrs="select('@*')">
    <topmenu id="menu-items"></topmenu>
</body>

CHILD:

<body>
    <div py:match="topmenu" py:attrs="select('@*')"><span>item1</span></div>
</body>

使用 py:match 通常比您使用的更复杂需要,我建议您查看快速入门模板内的页眉和页脚实现,它们使用更简单的方法来管理可重用模板部分。

对于菜单特定情况,您还可以查看 tgext.menu 它使得涡轮齿轮应用程序中的菜单和导航栏很容易处理。

Genshi py:match is a bit harsh to understand. The TurboGears2 documentation explains the concept quite well: "given an XPath expression, it finds and replaces every element in the template that matches the expression – with the content of the element containing the py:match."

This means that actually the element that has the py:match replaces the one that doesn't have it. So if you want to put the menu inside the master from the child template you should invert the two:

MASTER:

<body py:match="body" py:attrs="select('@*')">
    <topmenu id="menu-items"></topmenu>
</body>

CHILD:

<body>
    <div py:match="topmenu" py:attrs="select('@*')"><span>item1</span></div>
</body>

Using py:match is often more complex than what you need, I suggest you to take a look at the header and footer implementation inside the quickstart template, they use an easier way to manage reusable template parts.

For the menu specific case you can also take a look at tgext.menu it makes quite easy to handle menus and navbars inside turbogears applications.

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