Search code examples
odoobreadcrumbsportalodoo-12

own pages/templates don't genereate page_name


I am trying to add a breadcrumb entry to portal pages. I try to copy form the sale module. Inside this module there is this template that adds new breadcrumb entries:

    <template id="portal_my_home_menu_sale" name="Portal layout : sales menu entries" inherit_id="portal.portal_breadcrumbs" priority="20">
        <xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
            <li t-if="page_name == 'quote' or sale_order and sale_order.state in ('sent', 'cancel')" t-attf-class="breadcrumb-item #{'active ' if not sale_order else ''}">
                <a t-if="sale_order" t-attf-href="/my/quotes?{{ keep_query() }}">Quotations</a>
                <t t-else="">Quotations</t>
            </li>
            <li t-if="page_name == 'order' or sale_order and sale_order.state not in ('sent', 'cancel')" t-attf-class="breadcrumb-item #{'active ' if not sale_order else ''}">
                <a t-if="sale_order" t-attf-href="/my/orders?{{ keep_query() }}">Sales Orders</a>
                <t t-else="">Sales Orders</t>
            </li>
            <li t-if="sale_order" class="breadcrumb-item active">
                <span t-field="sale_order.type_name"/>
                <t t-esc="sale_order.name"/>
            </li>
        </xpath>
    </template>

The templates I created don't have a page_name attribute. How can I add this to my templates? Stock portal pages have home, order, or invoice as page_name but I couldn't find that in stock templates.


Solution

  • Variables settings are added either at the time of calling the render function or using t-set inside the template, or both.

    On your particular case, page_name gets assigned inside portal_my_quotes (See <path_to_v12>/addons/sale/controllers/portal.py lines 39-90. See an excerpt below.) which is the controller for the route /my/quotes

    @http.route(['/my/quotes', '/my/quotes/page/<int:page>'], type='http', auth="user", website=True)
    def portal_my_quotes(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
        values = self._prepare_portal_layout_values()
        ...
        values.update({
            'date': date_begin,
            'quotations': quotations.sudo(),
            'page_name': 'quote',
            'pager': pager,
            'archive_groups': archive_groups,
            'default_url': '/my/quotes',
            'searchbar_sortings': searchbar_sortings,
            'sortby': sortby,
        })
        return request.render("sale.portal_my_quotations", values)
    

    Documentation regarding the use of t-set can be found at https://www.odoo.com/documentation/12.0/reference/qweb.html#setting-variables