Skip to Content
Menu
This question has been flagged
2 Replies
910 Views

Hi everyone, I'm trying to develop a custom theme for my odoo (v13) website but I'm struggling to create templates using qWeb and calling odoo defined templates like:


<template id="template_header_custom" inherit_id="website.layout" name="Template Header Cutsom" active="True">

<xpath expr="//header//nav" position="replace">

<h1>Custom header</h1>

<div>

<t t-call="website.navbar_nav">

<t t-set="_nav_class" t-valuef="me-auto"/>


<!-- Menu -->

<t t-foreach="website.menu_id.child_id" t-as="submenu">

<t t-call="website.submenu">

<t t-set="item_class" t-valuef="nav-item"/>

<t t-set="link_class" t-valuef="nav-link"/>

</t>

</t>

</t>

</div>

</xpath>

</template>

As soon as I invoque a website addon template I get the following error (once I've loaded the theme, navigate to the website home):


Error Message:
load could not load template ValueError: View 'website.navbar_nav' in website 1 not found Template: website.layout Path: /t/html/body/div/header/div[2]/t

How am I supposted to load these templates so I can create a custom dynamic layout for my theme?


Avatar
Discard
Author

Hi, thanks for the quick replay.

Yes in fact I've checked the three points:


{

'name': 'Custom theme',

'description': 'Odoo custom theme',

'version': '1.0',

'author': 'Luis H. Porras',

'category': 'Theme/Creative',

'depends': ['website', 'website_theme_install'],

'data': [

'views/assets.xml',

'views/layout.xml',

'views/pages.xml',

'views/snippets.xml',

'views/options.xml'

],

}

  • And code correctess, well, the code it's been copy/pasted

So I understand from your replay that I'm doing the process as expected but for some reason I don't get the desired output. Searching in the design_themes repo I also found this approach but didn't work either:

theme_models.py

from odoo import models


class CustomTheme(models.AbstractModel):

_inherit = 'theme.utils'


@property

def _header_templates(self):

return ['theme_custom.template_header_custom'] + super()._header_templates


@property

def _footer_templates(self):

return ['theme_custom.template_footer_custom'] + super()._footer_templates


def _theme_custom_post_copy(self, mod):

self.enable_view('theme_custom.template_header_custom')

self.enable_view('theme_custom.template_footer_custom')

__init__.py (under models subfolder)

from . import theme_models

__init__.py (main folder)

from . import models

Any other ideas on how to debug this or any other workaround?

Thanks!

Best Answer
  • Ensure Template Availability: Confirm that the website.navbar_nav and website.submenu templates exist in the website module. If they are not loaded or accessible, you won't be able to call them in your custom template.
  • Check for Module Dependencies: Make sure your custom theme module has a dependency on the website module. In the __manifest__.py file of your theme module, you should have:

'depends': ['website'],
  • Correct Template Call: Ensure that the template you're calling exists in the correct format and the call is made correctly. In your case, t-call="website.navbar_nav" and t-call="website.submenu" seem correct, but double-check that these templates are properly defined in the website module.
Avatar
Discard
Author

Hi, thanks for the quick replay.

Yes in fact I've checked the three points:

website.navbar_nav template definition.
Manifest:

{

'name': 'Custom theme',

'description': 'Odoo custom theme',

'version': '1.0',

'author': 'Luis H. Porras',

'category': 'Theme/Creative',

'depends': ['website', 'website_theme_install'],

'data': [

'views/assets.xml',

'views/layout.xml',

'views/pages.xml',

'views/snippets.xml',

'views/options.xml'

],

}

And code correctess, well, the code it's been copy/pasted

So I understand from your replay that I'm doing the process as expected but for some reason I don't get the desired output. Searching in the design_themes repo I also found this approach but didn't work either:

theme_models.py

from odoo import models

class CustomTheme(models.AbstractModel):

_inherit = 'theme.utils'

@property

def _header_templates(self):

return ['theme_custom.template_header_custom'] + super()._header_templates

@property

def _footer_templates(self):

return ['theme_custom.template_footer_custom'] + super()._footer_templates

def _theme_custom_post_copy(self, mod):

self.enable_view('theme_custom.template_header_custom')

self.enable_view('theme_custom.template_footer_custom')

__init__.py (under models subfolder)

from . import theme_models

__init__.py (main folder)

from . import models

Any other ideas on how to debug this or any other workaround?

Thanks!

Author

Hi Asliddin, I was re-reading your answer and wonder if there is a specific way of checking he availability of the templates in run-time as my response to your answer is based in checking the official repo code.

Author Best Answer

Re-reading Asliddin answer I've found the  problem. 

In fact the template website.navbar_nav doesn't exist in Odoo v13.0 yet. My former link to  the code is pointing to a later version of Odoo.


Avatar
Discard
Related Posts Replies Views Activity
1
May 25
238
2
Apr 25
359
0
Apr 25
338
2
Apr 25
348
0
Mar 25
779