Enable Dark Mode!
how-to-create-website-menu-and-page-odoo-12.png
By: Meera K

How to Create a Website Menu and Page in Odoo 12

Technical Odoo 12

Boost your business with integrated business applications. This is what Odoo proclaims and practice. The open-source ERP is known for its simplicity and usability in various business domains. With abundant support of a large community of Odoo developers, the application is constantly improvised and extended.

The latest version Odoo 13 has come up with various new and improved features in the application. From the accounting module to the website, Odoo has brought several changes bringing great profits to the business community.

With no much ado let's get to the topic.

This blog sprinkles the highlight of Odoo website. Well, we know creating a website menu and website page is no strenuous task in Odoo. The individuals can straight away create a new website menu or a website page from the frond-end of Odoo. However, one can also create them via making use of the custom module.

Let’s see how to create a website menu and page using the custom module in Odoo 12.

To create a website menu, firstly create a record in XML very much like in the following code,

  <?xml version="1.0" encoding="utf-8"?>
<odoo>
   <data>
       <record id="test_menu" model="website.menu">
           <field name="name">Test</field> <!-- Name of the menu-->
           <field name="url">/test</field>
           <field name="parent_id" ref="website.main_menu"/>
           <field name="sequence" type="int">80</field>
              <!--sequence of the menu-->
       </record>
   </data>
</odoo>

Provide the name, URL, parent id and the order of the menu.
A menu “Test” will be created. On clicking the menu, a call will be passed to the controller which contains the URL (ie here ‘/test’).
  
Either you can render a template or you can redirect to a page from the controller using controller ‘/test’.

To create a new page, create a .xml file and do the following:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
     <record id="demo_page" model="website.page">
         <field name="name">Demo</field>
         <field name="website_published">True</field>
         <field name="url">/demo</field>
         <field name="type">qweb</field>
         <field name="key">web_demo_page.test_page</field>
         <field name="arch" type="xml">
             <t t-name="web_demo_page.test_page">
                 <!--  Page Contents -->               
             </t>
         </field>
     </record>
 </odoo>

In the above code, we created a record with type = “qweb”  and then wrapped the page content (HTML code) inside the <t> tag. Either we can create a page like this or we can create a template explicitly by using <template> tag and then we can call the template from the record as in the following code.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
   <record id="demo_page" model="website.page">
        <field name="name">Demo</field>
        <field name="website_published">True</field>
        <field name="url">/demo</field>
        <field name="view_id" ref="demo_page_template"/>
        <!-- Provide  template id that you want to render --> 
    </record>
    <template id="demo_page_template">
        <t t-call="website.layout">
            <div id="wrap">
                <div class="container">
                   <!-- Page Contents -->                      
                </div>
            </div>
        </t>
    </template>
</odoo>

So when we render the page, it will display the contents in the template that we provided as in the view_id.

To create a menu for the above page, do the following: 

<record id="demo_page_menu" model="website.menu">
  <field name="name">Demo</field>
  <field name="page_id" ref="demo_page"/>
  <field name="parent_id" ref="website.main_menu" />
  <field name="sequence" type="int">85</field>
</record>


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message