11

I want to create a new theme for odoo. I have done it by create a new module and install it. I see in this document here which said that odoo support template inheritance by using t-extend keyword. However I can't make it. This is my customized template:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
    <template id="website.homepage" name="Homepage" page="True">
        <div class="header">
            <h1>FOO<h1>
            <div class="main">
            </div>
        </div>
    </template>

    <template id="website.contact" name="Homepage" page="True">
        <t t-extend="website.homepage">
            <t t-jquery="div.main" t-operation="inner">
                <h1>FOO 2</h1>
            </t>
        </t>
    </template>

</data>
</openerp>

Template website.contact should have showed FOO and FOO 2 but it only showed FOO 2. Please help me explain it. Thanks.

Minh-Hung Nguyen
  • 1,164
  • 1
  • 15
  • 21

5 Answers5

11

You use a syntax for client side templates, but those are server side templates. You use inheritance with server side templates this:

<template id="contact" inherit_id="website.homepage">
    <xpath expr="//div[@class='main']" position="inside">
        <h1>FOO 2</h1>
    </xpath>
</template>

You can read more in the official documentation.

Ludwik Trammer
  • 24,602
  • 6
  • 66
  • 90
  • Do as you said, it modifies the page website.homepage, not create a new page (website.contact). Is there anyway to create a new page which inherit from a page and doesn't change the original one? – Minh-Hung Nguyen Dec 23 '14 at 00:32
  • And seems that it's client side, not server side template, what I did is follow this instruction: http://odoo-80.readthedocs.org/en/latest/guides/themes.html – Minh-Hung Nguyen Dec 23 '14 at 00:39
  • @Minh-Hung Nguyen Those are server side templates (i.e. they are evaluated on the server side) - you link to a correct guide, but the guide doesn't mention `t-extend` anywhere precisely because it's a guide for server side templates, and `t-extend` is a client side (JavaScript) templates feature. – Ludwik Trammer Dec 23 '14 at 09:38
  • 2
    I think part of your confusion may come from the fact that inheritance in Odoo doesn't typically *create* a new object. It *modifies* an existing object in place. To create a new template based on another templates features you may want to use `t-call` instead. – Ludwik Trammer Dec 23 '14 at 09:42
  • Thanks for your answer, could you please tell me in which case can we use t-extend? – Minh-Hung Nguyen Dec 23 '14 at 16:12
  • For example when creating widgets for Odoo (the ERP system itself, not an Odoo-powered website). – Ludwik Trammer Dec 23 '14 at 16:24
1

You are trying to create new theme.? and are you using odoo 8.0.? I am asking this because the link you posted is for OpenERP 7.0 So for Odoo 8.0 new documentation is available see here and for QWEB you can find it here QWEB.

Now Main thing if you are trying to create new theme for CMS or Website module then you must go through these steps.

Bazzinga...
  • 996
  • 2
  • 16
  • 26
  • Thank you for your links, I am using odoo 8 but seems that I watched wrong docs. I tried replace t-extend by t-extends but still unsuccess. – Minh-Hung Nguyen Dec 24 '14 at 11:03
1

Using Xpath here you can Inherit and make changes on parent tempaltes, examples follows.

    <template id="homepage_extend" inherit_id="website.homepage">
      <xpath expr="//div[@class='main']" position='inside'>
        <h1>FOO 2</h1>
      </xpath>
    </template>

or try

  <template id="homepage_extend" inherit_id="website.homepage">
      <xpath expr="//div[@class='header']" position='replace'>
        <div class="header">
          <h1>FOO<h1>
          <div class="main">
            <h1>FOO 2</h1>
          </div>
       </div>
      </xpath>
    </template>

You can also try these by overriding that template like:

 <template id="website.homepage">
    <div class="header">
        <h1>FOO<h1>
        <div class="main">
          <h1>FOO 2<h1>
        </div>
    </div>
</template>

while overriding don't forget to gave the exact id followed by module name. Cheers !

0

In parent template, add <t t-raw="0"/> or <t t-raw="name"/>, template: ...code html...

https://www.odoo.com/documentation/9.0/reference/qweb.html

GiangSoda
  • 1
  • 1
-1

Hello Minh-Hung Nguyen,

Try this code,

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
    <template id="website.homepage" name="Homepage" page="True">
        <div class="header">
            <h1>FOO<h1>
            <div class="main">
            </div>
        </div>
    </template>

    <template id="website.contact" name="Homepage" page="True">
        <t t-extend="website.homepage">
            <!-- Use 'append' to add the h1 tag inside main div -->
            <t t-jquery="main" t-operation="append">
                <h1>FOO 2</h1>
            </t>
        </t>
    </template>

</data>
</openerp>

I hope my answer is helpfull for you.

Mayur Vora
  • 922
  • 2
  • 14
  • 25