Enable Dark Mode!
how-to-create-a-snippet-in-odoo-18.jpg
By: Anfas Faisal K

How to Create a Snippet in Odoo 18

Technical

Odoo 18 provides powerful website management tools, allowing users to create and customize websites efficiently. These tools include a user-friendly drag-and-drop feature for snippets, making it easy to design and structure content on web pages. Snippets in Odoo are categorized into two main types:

* Static Snippets: Fixed content that remains unchanged until modified by the user.

* Dynamic Snippets: Content dynamically retrieved from the Odoo backend based on datasets.

In this blog, we will go through the steps to create a static snippet in Odoo 18.

Steps to Create a Static Snippet

1. Create a Template for the Snippet

A snippet in Odoo is defined as an XML template. Below is an example of a basic snippet:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="basic_snippet_template" name="Basic Snippet">
        <section class="container">
            <div class="row">
                <div class="col-md-12">
                    <h1>Basic Snippet</h1>
                    <p>This is a basic snippet used to demonstrate snippet functionality in Odoo 18.</p>
                </div>
            </div>
        </section>
    </template>
</odoo>

2. Register the Snippet in the Website Editor

To make the snippet available in the website editor, extend the website.snippets template and include the snippet:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>   
    <template id="basic_snippet_banner" inherit_id="website.snippets"
              name="Snippet banner">
        <xpath expr="//snippets[@id='snippet_groups']"
               position="inside">
            <t t-snippet="basic_snippet.basic_snippet_template"
               t-thumbnail="/basic_snippet/static/src/images/snippets/banner.jpg"/>
        </xpath>
    </template>
</odoo>

3. Add the Snippet File to __manifest__.py

Make sure the XML file that defines the snippet is included in the data section of the module's manifest file:

{
    'name': 'Website Custom Snippet',
    'version': '18.0.1.0.0',
    'category': 'Website',
    'depends': ['website'],
    'data': [
        'views/basic_template.xml',
    ],
}

4. Install or Upgrade the Module

After installing or updating the module, go to the website editor, click 'Edit', and locate the snippet within the 'Features' section. You can then drag and drop it onto your page as needed.

How to Create a Snippet in Odoo 18-cybrosys

Conclusion

Creating snippets in Odoo 18 is straightforward and enhances the customization of website pages. By following these steps, you can create static snippets that provide structured and reusable content blocks.

To read more about How to Create a Snippet in Odoo 17, refer to our blog How to Create a Snippet in Odoo 17.


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