繁体   English   中英

如何在 Odoo14 中扩展 qweb 模板?

[英]How to extend qweb templates in Odoo14?

我正在尝试在过滤器的下拉列表中添加自定义菜单项

在 Odoo14 和 owl 框架中,一些菜单项存在于以下代码段内的基本模块中

<t t-name="web.CustomFilterItem" owl="1">
    <div class="o_generator_menu">
        <button type="button"
            class="o_add_custom_filter dropdown-item"
            aria-expanded="false"
            t-ref="fallback-focus"
            t-on-click="state.open = !state.open"
            t-on-keydown="_onKeydown"
            >
            <t>Add Custom Filter</t>
        </button>
    </div>
</t>


所以在我的自定义模块中,我正在执行以下操作来添加自定义项

<?xml version="1.0" encoding="UTF-8" ?>
<templates>
    <t t-extend="web.CustomFilterItem">
        <t t-jquery=".o_add_custom_filter" t-operation="after">
            <div
                role="separator"
                class="dropdown-divider o_generator_menu"
            />
            <button
                type="button"
                class="dropdown-item o_generator_menu o_add_advanced_search"
                aria-expanded="false"
            >Custom Item</button>
        </t>
    </t>
</templates>

但它没有出现。 有什么建议么?

Odoo14 owl 框架,您可以使用 xpath 扩展模板。

你可以这样使用。

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="CustomFilterItem" t-inherit="web.CustomFilterItem" t-inherit-mode="extension" owl="1">
<xpath expr="//button[hasclass('o_add_custom_filter dropdown-item')]" position="before">
//your code
</xpath>
</templates>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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