关于QWeb模板继承20170419

2 篇文章 0 订阅

官方关于QWeb模板继承的说明

template inheritance

Template inheritance is used to alter existing templates in-place, e.g. to add information to templates created by an other modules.

Template inheritance is performed via the t-extend directive which takes the name of the template to alter as parameter.

The alteration is then performed with any number of t-jquery sub-directives:

<t t-extend="base.template">
    <t t-jquery="ul" t-operation="append">
        <li>new element</li>
    </t>
</t>

The t-jquery directives takes a CSS selector. This selector is used on the extended template to select context nodes to which the specified t-operation is applied:

append
the node's body is appended at the end of the context node (after the context node's last child)
prepend
the node's body is prepended to the context node (inserted before the context node's first child)
before
the node's body is inserted right before the context node
after
the node's body is inserted right after the context node
inner
the node's body replaces the context node's children
replace
the node's body is used to replace the context node itself
No operation

if no t-operation is specified, the template body is interpreted as javascript code and executed with the context node as this

原XML文件(picking.xml 部分)


 
 
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name='PickingEditorWidget'>
<td class="brctbl-col5 js_loc">
<t t-esc="row.cols.dest" />
<div class="pull-right btn-group">
<button type="button" class="btn btn-default dropdown-toggle fa fa-cog" data-toggle="dropdown">
 <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<t t-if="row.cols.product_id">
<li><a class="js_create_lot" href="#">Create / Change Lot</a></li>
</t>
<t t-if="!row.cols.head_container && !row.cols.container">
<li><a class="js_change_src" href="#">Change source location</a></li>
<li><a class="js_change_dst" href="#">Change destination location</a></li>
</t>
<t t-if="row.cols.head_container">
<li><a class="js_pack_change_dst" href="#">Change destination location</a></li>
<li class="divider"></li>
<li><a class="js_pack_configure" href="#">Configure package</a></li>
<li><a class="js_delete_pack" href="#">Remove from package</a></li>
<li><a class="js_print_pack" href="#">Print package label</a></li>
</t>
</ul>
</div>
</td>
</t>
</templates>


如果要在css样式为brctbl-col5 的<td> 后面增加1个<td>

创建picking.xml文件,写法:


 
 
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
    <t t-extend="PickingEditorWidget">
        <t t-jquery=".brctbl-col5" t-operation="after">
            <td>
                <t t-if="row.cols.head_container">
                    <select id="js_loc_select2" class="form-control pack">
                        <option class="js_loc_option" data-loc-id="false">更改目标位置...</option>
                        <t t-foreach="widget.get_location()" t-as="loc">
                            <option class="js_loc_option" t-att-data-loc-id="loc.id"><t t-esc="loc.name"/></option>
                        </t>
                    </select>
                </t>
                <t t-if="!row.cols.head_container &amp;&amp; !row.cols.container">
                    <select id="js_loc_select2" class="form-control">
                        <option class="js_loc_option" data-loc-id="false">更改目标位置...</option>
                        <t t-foreach="widget.get_location()" t-as="loc">
                            <option class="js_loc_option" t-att-data-loc-id="loc.id"><t t-esc="loc.name"/></option>
                        </t>
                    </select>
                </t>
            </td>
        </t>
    </t>
</templates>

-------------------------------------------------------------------------------------------------------------------------

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值