Search code examples
pythonodooodoo-13

how to limit website content visibility by group odoo 13


I have content on the website that is part of a subscription. based on the subscription I will add the user to a group how to show content based on the group in the home page

also to hide some part of the page is the user (is login)

my code of

  <template id="custom_header" inherit_id="website.layout" name="Custom Header">
    <xpath expr="//div[@id='wrapwrap']/header" position="attributes">
      <attribute name="id">my_header</attribute>
      <attribute name="group">base.group_public</attribute>
    </xpath>
  </template>

Solution

  • You can do it like this one that you can find in addons/portal/views/portal_templates.xml.

                    <div class="collapse navbar-collapse" id="top_menu_collapse">
                        <ul class="nav navbar-nav ml-auto text-right" id="top_menu">
                            <li class="nav-item divider" t-ignore="true" t-if="not user_id._is_public()"/>
                            <li class="nav-item dropdown" t-ignore="true" t-if="not user_id._is_public()">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
                                    <b>
                                        <span t-esc="user_id.name[:23] + '...' if user_id.name and len(user_id.name) &gt; 25 else user_id.name"/>
                                    </b>
                                </a>
                                <div class="dropdown-menu js_usermenu" role="menu">
                                    <a id="o_logout" class="dropdown-item" t-attf-href="/web/session/logout?redirect=/" role="menuitem">Logout</a>
                                </div>
                            </li>
                        </ul>
                    </div>
    

    the method _is_public() return True if the "user" is not logged else false