Skip to Content
Menú
This question has been flagged
1 Respondre
2055 Vistes

Do you have an example of how to pass a value from a controller to an OWL template? I haven't found a single article discussing this.

Avatar
Descartar
Best Answer

Hi,

For passing the value from the controller to the template, try to use the following code:

Python:# -*- coding: utf-8 -*-

from odoo import http

from odoo.http import request


class ExampleController(http.Controller):


    @http.route('/example', auth='public', website=True)

    def example(self):

        message = "Hello, World!"

        return request.render('your_module.example_template', {'message': message})


XML:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="example_template" name="Example Template">
        <t t-call="website.layout">
            <div id="wrap">
                <div class="container">
                    <h1 t-esc="message"/>
                </div>
            </div>
        </t>
    </template>
</odoo>



Hope it helps.


Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de juny 24
1537
2
de jul. 25
522
0
de gen. 25
935
0
de des. 24
1716
0
de set. 24
947