模板template定义
t-name
只能放在模板文件的最外面,离template
标签最近的地方
<templates>
<t t-name="template-name">
<!-- template code -->
</t>
</templates>
它没有其他参数,但可以使用一个t
标签,当使用t
标签时它需要有单个子元素,模板名可以随便取,一般会用.
分隔来表示继承关系。
模板template继承
模板继承是用来修改已存在的模板,即给在其他模块定义的模板添加内容。通过t-extend
来表示,它的值是被继承的模板名,通过t-jquery
来进行修改。
<t t-extend="base.template">
<t t-jquery="ul" t-operation="append">
<li>new element</li>
</t>
</t>
t-jquery
给出的是一个css
选择器,用于选择需要改变的节点,并通过t-operation
指定需要进行的操作。
- append - 新节点的内容添加到原节点的后面(最后一个子节点后)
- prepend - 新节点内容添加到原节点前面(第一个子节点前)
- before - 新节点内容添加到原节点前
- after - 新节点内容添加到原节点后
- inner - 新节点内容替换原节点的子节点
- replace - 新节点内容直接替换原节点
如果没有指定operation
,那么模板内容会被解析成javascript节点,并将context
节点设置为this
。