Enable Dark Mode!
how-to-create-inner-content-snippets-in-odoo-19.jpg
By: Najiya Rafi

How to Create Inner Content Snippets in Odoo 19?

Technical Odoo 19 Odoo Enterprises Odoo Community

The Odoo Website Builder has long supported the ability to create Inner Content Snippets, which is a powerful feature for developers that allows specialized building blocks to be nested inside parent containers such as Intro sections, Accordions, Tabs, or custom containers. This modular approach to page design lets you compose rich layouts by combining reusable inner blocks within a single parent structure, giving developers fine-grained control over how content is organized and displayed on the page. You can make flexible designs by assembling various elements inside the parent element to form one page.

What is an Inner Content Snippet?

While normal snippets can be simply pulled down and placed anywhere on the body of the page, Inner Content Snippets are intended to live inside certain 'drop-zones' of other building blocks.

Let’s create a module to demonstrate an inner content snippet in Odoo 19.

How to Create Inner Content Snippets in Odoo 19?-cybrosys

Module Structure

A clean and Odoo-compliant structure looks like this:

How to Create Inner Content Snippets in Odoo 19?-cybrosys

Step 1: Define the Snippet Template

First, we need to define the HTML structure of our snippet. This is done using QWeb templates in an XML file.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
   <!-- Snippet Template -->
   <template id="s_inner_content_demo" name="Inner Content Demo">
       <section class="s_inner_content_demo pt32 pb32 o_colored_level">
           <div class="container lead">
               <div class="row align-items-center">
                   <div class="col-lg-12 text-center">
                       <i class="fa fa-star fa-3x text-primary mb-3"/>
                       <h3>Inner Content Snippet</h3>
                       <p>This snippet is registered as "inner content" and can be dropped into containers like Accordions or Tabs.</p>
                   </div>
               </div>
           </div>
       </section>
   </template>
</odoo>

Step 2: Register the Snippet in the Website Builder

To make the snippet appear in the "Inner Content" list, we must inherit the base website.snippets template and append our snippet to the snippet_content group.

<template id="snippets" inherit_id="website.snippets">
   <xpath expr="//snippets[@id='snippet_content']" position="inside">
       <t t-snippet="website_inner_content_demo.s_inner_content_demo"
          string="Inner Content Demo"
          t-thumbnail="/website_inner_content_demo/static/src/img/s_inner_content_demo.svg"/>
   </xpath>
</template>

How to Create Inner Content Snippets in Odoo 19?-cybrosys

Step 3: Register the Selector via JavaScript Plugin

This is the most critical step in Odoo 19. You must tell the Website Builder that your snippet is valid "inner content" by adding its selector to the so_content_addition_selector resource.

import { Plugin } from "@html_editor/plugin";
import { registry } from "@web/core/registry";
class InnerContentDemoPlugin extends Plugin {
   static id = "InnerContentDemoPlugin";
   resources = {
       // Register the selector as valid inner content
       so_content_addition_selector: [".s_inner_content_demo"],
   };
}
// Register the plugin in the correct category
registry.category("website-plugins").add(InnerContentDemoPlugin.id, InnerContentDemoPlugin);

How to Create Inner Content Snippets in Odoo 19?-cybrosys

Step 4: Add Snippet Styling

To make your snippet look professional, add some SCSS styling.

.s_inner_content_demo {
   background-color: rgba($primary, 0.05);
   border: 2px dashed rgba($primary, 0.2);
   border-radius: 8px;
   padding: 20px;
   margin: 10px 0;
   transition: all 0.3s ease;
   &:hover {
       background-color: rgba($primary, 0.1);
       border-color: $primary;
   }
   h3 {
       color: $primary;
       font-weight: bold;
   }
}

How to Create Inner Content Snippets in Odoo 19?-cybrosys

Step 5: Bundle the Assets

Finally, ensure all your files are correctly listed in the __manifest__.py. In Odoo 19, the builder plugins should be included in the website.website_builder_assets bundle.

How to Create Inner Content Snippets in Odoo 19?-cybrosys

The creation of internal content snippets within Odoo version 19 is quite easy to do once you grasp how the QWeb template connects to the JavaScript builder plugin. You can refer to this blog to create a more interactive and flexible website experience for your users.

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


Frequently Asked Questions

What is the difference between a standard snippet and an inner content snippet in Odoo 19?

A standard snippet is designed to be dropped directly onto a page section, while an inner content snippet is meant to be placed inside other snippets like tabs, accordions, or custom containers. Inner snippets require additional configuration, such as registering a selector via a JavaScript plugin.

Why is the JavaScript plugin required for inner content snippets?

In Odoo 19, simply defining a QWeb template is not enough. The Website Builder needs to know where a snippet is allowed to be dropped. The plugin registers your snippet using so_content_addition_selector, making it usable inside specific containers.

Where should I register my inner content snippet in the snippet panel?

Inner content snippets should be added under the snippet_content section of website.snippets, not under snippet_structure. This ensures they appear in the correct panel when editing nested content areas.

Can I use inner content snippets inside custom snippets?

Yes, but your custom snippet must define a valid drop zone compatible with Odoo's editor. If the container supports inner content (like tabs/accordion), your snippet will work as long as the selector is properly registered.

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