3

I am trying to make a report but without using external_layout or internal_layout because they have headers in them. I wanted to have my own header and footer.

I have tried using minimal_layout because it seems it is the less busy layout compared to other layouts.

But I kept having error body_parent = root.xpath('//main')[0] IndexError: list index out of range - - -

Here is my code

<template id="applicant_contract_css">
    <t t-call="web._assets_helpers"/>
    <link rel="stylesheet" type="text/scss" href="/fhid_recruitment/static/src/css/applicant-contract.css"/>
</template>

<template id="minimal_layout" inherit_id="web.minimal_layout">
    <xpath expr="//head" position="inside">
        <t t-call-assets="fhid_recruitment.applicant_contract_css"/>
    </xpath>
</template>

<template id="applicant_contract_offering">
    <t t-call="web.minimal_layout">
        <t t-foreach="docs" t-as="o">
            <div class="header">
                My Header
            </div>
            <div class="article">
                Content
            </div>
            <div class="footer">
                My footer
            </div>
        </t>
    </t>
</template>

How do I use minimal layout? or is there another layout should I use?

strike_noir
  • 4,080
  • 11
  • 57
  • 100

2 Answers2

4

When you want create a template report you need to at least call, "web.html_container" witch call "web.report_layout" witch define Minal Report layout .

all css file for report template should be add to report_assets_common template:

<template id="assets_common" name="a proper name for your template purpuse" inherit_id="web.report_assets_common">
    <xpath expr="." position="inside">
        <link rel="stylesheet" type="text/scss" href="/fhid_recruitment/static/src/css/applicant-contract.css"/>
    </xpath>
</template>

It's better to extract your header and footer to template so you use them in multiple report, like the external_layout, you can take a look at the external_layout_standard to get the basic Idea.

<template id="external_layout">
    <div class="header">
        My Header
    </div>
    <!-- everything inside t-call="fhid_recruitment.external_layout" will be rendered here -->
    <t t-raw="0" />

    <div class="footer">
        My footer
    </div>
</template>

In the template just call your custom external layout here:

<template id="applicant_contract_offering">
    <t t-call="web.html_container">
        <!-- because it's defined in this module "fhid_recruitment" -->
        <t t-call="fhid_recruitment.external_layout">
           <t t-foreach="docs" t-as="o">
               <div call="page">
                    <div class="article">
                        Content
                    </div>
                </div>
            </t>
        </t>
    </t>
</template>

One of the most import thing you need to know about template is the <t t-raw="0" />, if for example a template x_template have this when we call it like this:

<t t-call="x_template">
    any_content
</t>

what the Qweb engine will do is, replace <t t-raw="0" /> inside the x_template with any_content when rendering the report.

To simplify things if you are going to use header and footer only for one template:

<template id="applicant_contract_offering">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <div class="header">
                My Header
            </div>
            <div class="article">
                Content
            </div>
            <div class="footer">
                My footer
            </div>
        </t>
    </t>
</template>
Charif DZ
  • 14,415
  • 3
  • 21
  • 40
1

You can inherit either external_layout or internal_layout and override the default behaviour with your custom code. And use it in your report.

KbiR
  • 4,047
  • 6
  • 37
  • 103