Development Book V17: Snippets

Odoo offers user-friendly and efficient website management tools, enabling users to easily create and customize websites. These tools include a drag-and-drop feature for snippets. The website editor in Odoo provides various editing building blocks that users can drag and drop onto their pages, customizing them as needed. Additionally, users can learn to create their own building blocks. Odoo categorizes snippets into two main types: static snippets, which remain fixed until modified by the user, and dynamic snippets, which are based on datasets and stored in the Odoo backend.

How to create a static snippet?

1. Create a template for the snippet.

<?xml version="1.0" encoding="UTF-8" ?>
<template id="basic_snippet" name="Basic Snippet">
      <section class="container">
          <div class="row">
              <div class="col-md-12">
                  <h1>Basic Snippet.........</h1>
                  <p>This is a basic snippet that is used to test the basic functionality of the snippets.</p>


2. Record the snippet as static

The provided XML code extends the website.snippets template in Odoo, specifically targeting the div with id='snippet_content.' It inserts a new snippet with the title 'blog_snippet.basic_snippet' after the last existing snippet in the designated position.

<template id="external_snippets" inherit_id="website.snippets" priority="8">
  <xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]" position="after">
       <t t-snippet="blog_snippet.basic_snippet"/>



Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message