Enable Dark Mode!
how-to-create-a-theme-module-in-odoo-19.jpg
By: Nivedhya T

How to Create a Theme Module in Odoo 19

Technical Odoo 19 Odoo Themes

The Website module in Odoo 19 has its own default theme, which works if there are no other themes present on the system. But users have the option to develop their own theme modules that they can deploy to their websites.

This article will take you through the process of developing a theme module for your website.

Start by installing the Website module.

How to Create a Theme Module in Odoo 19-cybrosys

After clicking the Activate button, you will be directed to a new page, from where you will be able to activate or change the theme.

In order to activate the theme, go to the website editor and then select the “Edit” option. Thereafter, select “Theme” and click on the Switch Theme button.

How to Create a Theme Module in Odoo 19-cybrosys

Now that we've talked about how to add and use a theme on the Odoo 19 website, let's move on to making a custom theme module in Odoo.

How to Create a Theme Module in Odoo 19-cybrosys

The picture above shows the files you need to make your own theme. The technical name of the theme should begin with "theme_" and then have a unique number for the theme.

The code snippets above show what is in the manifest file.

# -*- coding: utf-8 -*-
{
   'name': 'My Theme',
   'version': '19.0.1.0.0',
   'category': 'Theme/Sub Category',
   'summary': 'Theme summary',
   'depends': ['website'],
   'data': [
       'views/theme_views.xml',
      ],
   'assets': {
      'web.assets_frontend': [],
    },
}

Version: This tells you what version of the theme it is.

You need to fill in this field with "Theme" and then the name of its sub-category.

Summary: This gives a short overview of the theme.

Description: This gives details about the theme.

Depends: This gives the names of the list of modules on which the theme depends.

Data: This is the theme's data file.

Assets: These are assets of the theme.

Folders:

Static: This folder contains the src folder that has CSS files, img, js, and SCSS files.

Views: This contains website views including snippet templates, etc.

Structure of web pages:

There are three main elements that constitute the structure of a web page. These include header, body, and footer. Odoo provides these elements through its website.layout. If no customization is done on the template, then these elements would appear on their own. But these elements can be customized through inheritance of website.layout template.

Creating page layout:

In order to develop page layout in Odoo 19, one should create an XML file within the views folder.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="reflect_homepage" inherit_id="website.homepage" name="Reflect Home" priority="100">
<xpath expr="//div[@id='wrap']" position="replace">
<div id="wrap" class="oe_structure" style="background:#f7f7f7;">
<div class="container oe_structure">
<h1 class="test-heading"> This Is The Test Page </h1>
<ul class="test">
<li>The first feature of the Reflect Home is Feature 1</li>
<li>The second feature of the Reflect Home is Feature 2</li>
<li>The third feature of the Reflect Home is Feature 3</li>
</ul>
</div>
</div>
</xpath>
</template>
</odoo>

The screenshot below illustrates the page that has been modified according to the above description.

How to Create a Theme Module in Odoo 19-cybrosys

In order to reach the test page, a menu is needed. The menu will be created by inserting the following code into the test page item.

Now that we have our view and menu all set, we can beautify the test page by loading some CSS/SCSS files.

The content of style.scss is:

.test-heading {
  color: black;
}
.test {
  background: bisque;
  border-radius: 8px;
  padding: 0.8em;
  margin: 2em 0 3em;
  li {
     display: block;
     position: relative;
     padding: 2em;
     color: #FFF;
     text-align: center;
     margin-bottom: 1em;
     background-color: cadetblue;
     font-size: 1.0em;
  }
}

For the application of style.scss file to the newly created page, it needs to be integrated into the module’s manifest file as follows:

'assets': {
   'web.assets_frontend': [
       'theme_name/static/src/scss/style.scss',
   ],
},

Once done with the changes, the next step would be to update the theme for the changes to appear. This can be achieved by clicking on the Editor link in the website, and then selecting Theme under the Edit tab, followed by switching the theme and finally updating the theme.

Once the upgrade is completed, you will see the theme as depicted in the picture below:

How to Create a Theme Module in Odoo 19-cybrosys

One of the key aspects of Odoo is that we can integrate snippets within the website. Through this process, we can drag and drop the views that we require.

Then, let us proceed to look at the steps for creating an Odoo snippet.

  • Create an XML template
<template id="test_template" name="Test Snippet">
 <section class="container oe_structure">
   <h1 class="test-heading">Test Snippet</h1>
   <ul class="test">
     <li>Snippet Feature 1</li>
     <li>Snippet Feature 2</li>
     <li>Snippet Feature 3</li>
   </ul>
 </section>
</template>

  • Add the created snippet to the building blocks.
<template, id="test_template_snippet" inherit_id="website.snippets"
name="Category Highlight Snippet">
<xpath expr="//snippets[@id='snippet_groups]" position="inside">
<t t-snippet="theme_name.test_template"
t-thumbnail="/theme_name/static/src/images.jpeg"/>
</xpath>
<xpath expr="//snippets[@id='snippet_structure']" position="inside">
<t t-snippet="theme_name.test_template"/>
</xpath>
</template>

In the given case, the use of t-snippet makes it possible to link the snippet template to its corresponding block using the attribute theme_name.snippet_id. Likewise, the t-template attribute can be used to embed a template within a snippet block.

  • Incorporate the style files (CSS or SCSS) as previously indicated.
  • Include the test_snippet in the manifest file.
'data': [
   'views/theme_views.xml',
   'views/snippets.xml',
],
  • Complete the theme update according to the previous instructions.
  • Move to 'Edit' under the website settings and click on 'Blocks.' Within 'Structure,' find the newly created block.

The creation of a custom theme module in Odoo 19 enables developers to tailor the website appearance according to their requirements. The installation, activation, and customization of themes can be accomplished using a systematic methodology. This involves arranging the theme module files, defining the page layout design, applying style sheets using CSS or SCSS, and incorporating custom snippets to create additional functionality on the website. Through diligent effort and thorough testing, companies can create an appealing and functional website that aligns with their branding objectives.

To read more about How to Create a Module in Odoo 18, refer to our blog How to Create a Module in Odoo 18.


Frequently Asked Questions

What is a theme module in Odoo 19?

The theme module is a set of tools that lets you change how your website looks. Templates, snippets, css/scss styles, images, and other resources can all be part of a theme.

Why should I make my own theme instead of using one of the default ones?

With a custom theme, you can showcase your business’s visual identity, customize the layout to match your specific needs, and create new snippets with unique functionalities.

What do you need to do to make a theme in Odoo 19?

To create a theme in Odoo 19, you’ll need a good grasp of HTML, CSS/SCSS, and JavaScript, along with some familiarity with QWeb templates and how Odoo modules work. It also helps to be comfortable editing .xml files and to have a development setup where you can test your changes as you go.

What are the most important parts of an Odoo 19 theme module?

In an Odoo 19 theme module, the key parts include the __manifest__.py file for defining metadata and dependencies, along with folders like static/src/css for styling, static/src/js for JavaScript features, views for XML templates such as pages and snippets, and data for configuration or demo content all working together to shape the theme.

How do I add my own snippets to the theme module?

To add your own snippets in an Odoo 19 theme module, you can start by defining the snippet template in the views/snippets.xml file, then link it to a block using the t-snippet attribute. If needed, you can also use the t-template attribute to connect additional templates for more flexibility.

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