簡體   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