How to Create New Odoo Page, Menu and Mega Menu
  • /
  • Odoo Theme/
  • How to Create New Odoo Page, Menu and Mega Menu

In this tutorial, you will learn how to create new Odoo page, new menu and new mega submenu. We will make our menu bar dynamic so that it will show the links saved in the database.

Before continuing in this tutorial, make sure you have done our previous tutorials about Odoo theme Development Open .

Creating new Odoo page

Inside your views folder "theme_yourhome/views", create a new file and name it services_page.xml. There's already existing code in Odoo so go under addons folder "odoo-server/addons/website/data" and open website_data.xml. Search "contactus_thanks" because this is a good example that we can copy.

Creating new Odoo page

Copy the code and paste it in services_page.xml and change the details based on the page we will create.

Add it in services_page.xml to manifest.py file under data key so that our the record will be save in the database.

Restart Odoo and go to backend Settings -> Website -> Pick a Theme and click Update Theme. Go to browser and open link http://localhost:8069/service. You should see an empty page with the text.

services page no header footer

Adding Odoo default website layout with header and footer

Adding a new page without default layout is not ideal. Luckily, we can use default Odoo website template called "website.layout" to easily add header and footer across all website pages. We can do that by just calling website.layout template and add our template or design inside it.

Go back to the browser and reload the page. You will notice that website header and footer are showing on services page.

Odoo service page with website layout

Create Odoo page layout using bootstrap

Since Odoo already use bootstrap css framework by default, we can use this to build our services page. Copy the code below.

Add styles to our services page in "theme_yourhome/static/src/scss/styles.scss".

Then add background image to services page hero image. Download the image here Open and save it in "theme_yourhome/static/src/img/". Restart Odoo and go back to browser and refresh the page.

Odoo service page bootstrap

Making Odoo menubar dynamic

After creating a new page, we still have issue to the menu bar since it is still static. If you click any link, it doesn't go to that page. In order to make the menubar dynamic, we need to copy some code in Odoo website default header template.

Go to Odoo addons folder "addons/website/views" and open website_template.xml to PyCharm. Search header templates and copy the code like below:

Go to "theme_yourhome/views/header.xml" and paste it inside ul with class navbar-nav.

odoo navbar dynamic

Go back to the browser and refresh the page.

odoo navbar dynamic

Since we already added the dynamic menubar, we can remove all other static navigation links. As mentioned earlier, when installing Odoo website module, home and contact us page were automatically created. Copy the code below for updated navbar code.

Go to browser and refresh the page and you will see only two links, Home and Contact Us.

Creating new website page menu

Going back to website_data.xml file, search website.menu and copy the existing code for homepage menu or contact us page menu. Create a new file inside views folder "theme_yourhome/views/" and name it as menus.xml. Copy the code below.

Add this file into manifest file and restart Odoo.

Go to browser backend "Settings -> Website -> Pick a theme and click Update Theme. Go to Odoo frontend and refresh the page.

odoo service menu

Take note that once you added the menu, you can not edit it so you need to delete or comment the code, update theme and add or uncomment the code and update again the theme. But if you don't want to do this, you can still edit it by clicking in Pages and Edit Menu.

odoo edit menu

Now let's finish all the navigation links by fixing Sign In button on the right side of the menu bar. In the same file where we copy the code for the menubar, copy the code below and paste it to header.xml file - one for Sign In and another for logged in user.

Replace the current code of Sign In to the above code.

odoo sign-in

Go back to the browser and reload the page and notice the new dropdown link for logged in user.

odoo logged-in

Do the same think for mobile version. The complete header code will now be same like the below.

Creating Odoo mage submenu

To add Odoo mega submenu, the code is the same for normal menus, except that we will add two fields - is_mega_menu and mega_menu_content. Copy the code below and add it in "theme_yourhome/views/menus.xml" file.

Go to odoo backend and update the them then go to frontend and reload the page. You now have a new mega submenu.

odoo new mega-submenu

Congratulations, you have now successfully added a new page, a new menu and a new mega submenu. For more details, please check the video below.

How to Create New Odoo Page, Menu and Mega Menu