Odoo:继承网站页脚以将内容包装在div中

问题描述 投票:2回答:3

基本上,我想知道是否有一种方法可以继承website.footer_default来包装div中的部分内容。

举一个简短的例子,如果初始模板如下所示:

<template name="website.footer_default">
    <div id="footer">
        <content>
    </div>
</template>

我想用以下代替:

<template name="website.footer_default">
    <div id="footer">
        <div class="mynewdiv">
            <content>
        </div>
    </div>
</template>

有没有办法实现这一点,而无需复制/粘贴xpath内的所有内容?

我也尝试以qweb的方式继承这个模板,但代码似乎没有被执行。

有任何想法吗?

xml openerp
3个回答
1
投票

我找到了一种方法来实现这一目标,而不必重写所有内容,只有一个限制:它只适用于Web模板。

该解决方案使用javascript(以及Odoo网站与jquery捆绑在一起的事实)在运行时包装元素。

以下是代码方式:

<template name="new_footer_default" inherit_id="website.footer_default">
    <div id="footer" position="before">
        <script>
            $(document).ready(function(){
                $('#footer>*').wrapAll('<div class='mynewdiv'/>');
            });
        </script>
    </div>
</template>

0
投票

这对我有用。访问包含页脚的父项,并将其替换为包装原始代码的代码。

<openerp>
    <data>
        <template id="new_footer" inherit_id="website.layout">

            <xpath expr="//footer" position="replace">
                <footer>
                    <div class="mynewdiv">
                        <div id="footer_container">
                        </div>
                    </div>
                </footer>
            </xpath>

        </template>
    </data>
</openerp>

0
投票

在Odoo 11中你可以这样做:

<template name="new_footer_default" inherit_id="website.footer_default">
    <xpath expr="//div[@id='footer']" position="replace">
        <div id="footer">
            <div class="mynewdiv">$0</div>
        </div>
    </xpath>    
</template>

$ 0是添加替换节点内容的标记。它必须用作仅包含$ 0的文本节点(没有空格或其他文本)

https://www.odoo.com/documentation/11.0/reference/views.html(搜索替换)

© www.soinside.com 2019 - 2024. All rights reserved.