Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2027 มุมมอง

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 24
1519
2
ก.ค. 25
504
0
ม.ค. 25
919
0
ธ.ค. 24
1698
0
ก.ย. 24
922