Search code examples
webviewmenuodoohidden

Odoo - hide a website menu base on website fields


I have a website menu defined by this code:

        <record id="website_menu_apps" model="website.menu">
          <field name="name">Apps</field>
          <field name="url">/apps</field>
          <field name="parent_id" ref="website.main_menu" />
          <field name="sequence" type="int">19</field>
        </record>

and a field defined by this code:

class Website(models.Model):
        _inherit = 'website'
        dedicate_apps_store = fields.Boolean(string='Dedicated Apps Store', default=True)

How can I make website menu disappear when user set website.dedicate_apps_store to False?


Solution

  • <template id="custom_layout" inherit_id="website.layout" name="custom layout">
      <xpath expr="//ul[@id='top_menu']/t/t" position="attributes">
        <attribute name="t-if">submenu.name != 'Apps' or website.dedicate_apps_store</attribute>
      </xpath>
    </template>
    

    You inherit webiste.layout and set position="attributes" then you can write your condition inside the attribute tag.