Before this commit, defining a extension of a template by using the
combination of directives 't-name' and 't-extend' ignored potential
extensions that could have been defined beforehand.
For instance, let's assume the following templates.
```xml
<t t-name="a">
<div><span>1</span></div>
</t>
<t t-extend="a">
<t t-jquery="span" t-operation="replace">
<span>2</span>
</t>
</t>
<t t-name="b" t-extend="a">
<t t-jquery="div" t-operation="append">
<span>b</span>
</t>
</t>
```
Rendering template "b" displayed "1b" whereas we would expect "2b".
Moreover, when the extended template is itself an extension of
another template:
```xml
<t t-name="a">
<div><span>a</span></div>
</t>
<t t-name="b" t-extend="a">
<t t-jquery="div" t-operation="append">
<span>b</span>
</t>
</t>
<t t-name="c" t-extend="b">
<t t-jquery="div" t-operation="append">
<span>c</span>
</t>
</t>
```
Rendering template "a" displayed "a", template "b" displayed "ab",
but template "c" displayed "ac", whereas we would expect "abc".
With this commit, other extensions done to a template are kept when
a new extension is defined. It relies on the templates order, and
takes into account all extensions that have *already* been defined.
This is exactly how the new qweb inheritance mechanism (using
't-inherit' and 't-inherit-mode') behaves.
closes odoo/odoo#54315
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
63 lines
2.2 KiB
XML
63 lines
2.2 KiB
XML
<templates>
|
|
<!-- js-only -->
|
|
<t t-name="jquery-extend">
|
|
<ul><li>one</li></ul>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul" t-operation="append"><li>3</li></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul li:first-child" t-operation="replace"><li>2</li></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul" t-operation="prepend"><li>1</li></t>
|
|
<t t-jquery="ul" t-operation="before"><hr/></t>
|
|
<t t-jquery="ul" t-operation="after"><hr/></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul">this.attr('class', 'main');</t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul" t-operation="attributes"><attribute name="title" value="Main Title" /></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="ul" t-operation="attributes"><attribute name="name">main-ul</attribute></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="hr:eq(1)" t-operation="replace"><footer></footer></t>
|
|
</t>
|
|
<t t-extend="jquery-extend">
|
|
<t t-jquery="footer" t-operation="inner"><b>[[end]]</b></t>
|
|
</t>
|
|
<result id="jquery-extend"><![CDATA[
|
|
<hr/><ul class="main" title="Main Title" name="main-ul"><li>1</li><li>2</li><li>3</li></ul><footer><b>[[end]]</b></footer>
|
|
]]></result>
|
|
|
|
<t t-name="jquery-extend-clone" t-extend="jquery-extend">
|
|
<t t-jquery="ul" t-operation="append"><li>[[cloned template]]</li></t>
|
|
</t>
|
|
<result id="jquery-extend-clone"><![CDATA[
|
|
<hr/><ul class="main" title="Main Title" name="main-ul"><li>1</li><li>2</li><li>3</li><li>[[cloned template]]</li></ul><footer><b>[[end]]</b></footer>
|
|
]]></result>
|
|
|
|
|
|
<t t-name="a">
|
|
<div><span>Hi</span></div>
|
|
</t>
|
|
<t t-name="b" t-extend="a">
|
|
<t t-jquery="span" t-operation="after"><i>World</i></t>
|
|
</t>
|
|
<t t-name="c" t-extend="b">
|
|
<t t-jquery="span" t-operation="replace"><span>Hello</span></t>
|
|
</t>
|
|
<result id="a"><![CDATA[
|
|
<div><span>Hi</span></div>
|
|
]]></result>
|
|
<result id="b"><![CDATA[
|
|
<div><span>Hi</span><i>World</i></div>
|
|
]]></result>
|
|
<result id="c"><![CDATA[
|
|
<div><span>Hello</span><i>World</i></div>
|
|
]]></result>
|
|
</templates>
|