Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
12 Views

Hey Cyllo community, anyone know the best way to link website menus to controllers? I'm having a bit of trouble getting it to work right. Any tips appreciated!

Avatar
Discard

Here's how to create website menus in Odoo that link to controller routes. This approach uses XML to define the menu structure and Python to handle the route logic. To add website menus in Odoo that link to controller routes, you need to define them in XML using the 'website.menu' model and then create corresponding controller routes in Python.


The XML defines the menu's name, URL, parent menu, and sequence, while the Python code handles the logic for each route. Menus are declared using the 'website.menu' model in XML.
Each menu item specifies: 

name - Text displayed on the website navigation bar
url - pointing to a controller route
parent_id - for hierarchy
sequence - for ordering among menus. 

Adding Menus in an Example Module

 

   

   

      Page One

      /example/page1

     

     

   

   

   

      Page Two

      /example/page2

     

     

   

   

   

      Page Three

      /example/page3

     

     

   

 


Controller Example for Menus


from odoo import http
from odoo.http import request

class ExampleModule(http.Controller):
​@http.route('/example/page1', type='http', auth='public', website=True)
  ​def page_one(self, **kw): 
  ​return request.render('example_module.page1_template')

  ​@http.route('/example/page2', type='http', auth='public', website=True)
  ​def page_two(self, **kw): 
  ​return request.render('example_module.page2_template')

  ​@http.route('/example/page3', type='http', auth='public', website=True)
  ​def page_three(self, **kw):
  ​return request.render('example_module.page3_template')

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!