This question has been flagged
1 Reply
5953 Views

Thanks to some very valuable input from this forum I am making good progress on theming.

Now I would like to show a block of HTML on the home page only which looks like:

<template id="x_mytheme.home" name="My Home" page="True">
        <t t-call="x_mytheme.layout">
            <div id="maincol">
                ...[html]...
     
       </div>
</template>

For testing purposes I'm using a copy of website.layout which I'm editing:

<template id="x_mytheme.layout" name="My Layout">&lt;!DOCTYPE html&gt;
    ...[html]...
    
<div id="content-top" class="row">
        ....[html]...
    </div>
</template>

The HTML block needs to show below #content-top; I know this works when I inherit my layout:
<xpath expr="//div[@id='content-top']" position="after">
...
</xpath>

This affects every page that calls my layout though. How can I do this when this layout is called inside another view with t-call?

 

Btw, any idea how I can add this code below to source? Am I right in presuming it is stripped from the source before building the HTML?
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->

Is there any info on how Odoo handles this kind of conditional statements?

Cheers
Bruno

Avatar
Discard
Author Best Answer

I could solve this by using an if condition:

<div t-if="condition"> <p>Test</p> </div>

where condition is a check that the current view using the layout is the home page. But I can't figure out how to do that.

 

EDIT: I found it

I do this in my main layout:

<t t-if="xmlid == 'website.home'">
     <t t-call="x_mytheme.section"/>
 </t>

I tried with xml_id as I found that in the ORM guide, is there a way to have all these available variables or where can I learn more about them?

Thanks

Avatar
Discard