Skip to content

Commit 0d9dbe1

Browse files
committed
[IMP] howto/website_themes: Building blocks page update
- Change the Github urls to the correct version of Odoo - Adapt the way of creating a snippet template and how to add it to the builder - Add explanation about how to make a custom snippet "inner content" closes #12735 X-original-commit: eb0a61a Signed-off-by: Brandon Mercier (bram) <bram@odoo.com>
1 parent 7abfbbb commit 0d9dbe1

File tree

1 file changed

+97
-29
lines changed

1 file changed

+97
-29
lines changed

content/developer/howtos/website_themes/building_blocks.rst

Lines changed: 97 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Building blocks
55
Building blocks, also known as snippets, are how users design and layout pages. They are important
66
XML elements of your design.
77

8-
The building blocks are classified into four categories:
8+
The building blocks are classified into two types:
99

10-
#. **Structure blocks**: to give a basic structure to the website
11-
#. **Feature blocks**: to describe the features of a product or service
12-
#. **Dynamic Content blocks**: blocks that are animated or interact with the backend
13-
#. **Inner Content blocks**: blocks used inside other building blocks
10+
#. **Structure blocks**: visually used as "whole rows" and distributed into multiples categories
11+
(:guilabel:`Intro`, :guilabel:`Columns`, :guilabel:`Content`, :guilabel:`Images`,
12+
:guilabel:`People`, etc)
13+
#. **Inner Content blocks**: used inside other building blocks
1414

1515
At the end of this chapter, you will be able to :ref:`create custom snippets
1616
<website_themes/building_blocks/custom>` and to add them into a dedicated category.
@@ -427,15 +427,21 @@ snippet (e.g., :file:`001.js`, :file:`002.scss`).
427427
Custom snippet
428428
==============
429429

430-
To create a custom snippet, create first the snippet template. Then, add it to the list and make it
431-
available via the Website Builder.
430+
Some more specific needs will require the creation of custom snippets. Here is how to create a
431+
custom snippet/
432432

433433
.. _website_themes/building_blocks/custom/template:
434434

435435
Template
436436
--------
437437

438-
**Declaration**
438+
Create first the snippet template. Then, add it to the list and make it available via the Website
439+
Builder.
440+
441+
1. Declaration
442+
~~~~~~~~~~~~~~
443+
444+
First, create the template of the custom snippet:
439445

440446
.. code-block:: xml
441447
:caption: ``/website_airproof/views/snippets/s_airproof_snippet.xml``
@@ -464,25 +470,22 @@ Template
464470
- Avoid using ID attribute within your `section` as several instances of a snippet may appear
465471
throughout the page (An ID attribute has to be unique on a page).
466472

467-
Add your custom snippet to the list of standard snippets, so the user can drag and drop it on the
473+
Add the custom snippet to the list of standard snippets, so the user can drag and drop it on the
468474
page, directly from the edit panel.
469475

476+
2. Group creation
477+
~~~~~~~~~~~~~~~~~
478+
479+
Add a group at the top of the list (feel free to the put it where needed in this list).
480+
470481
.. code-block:: xml
471482
:caption: ``/website_airproof/views/snippets/options.xml``
472483
473-
<template id="snippets" inherit_id="website.snippets" name="Airproof - Custom Snippets">
474-
<xpath expr="//*[@id='default_snippets']" position="before">
475-
<t id="x_theme_snippets">
476-
<div id="x_theme_snippets_category" class="o_panel">
477-
<div class="o_panel_header">Theme</div>
478-
<div class="o_panel_body">
479-
<t t-snippet="website_airproof.s_airproof_snippet" t-thumbnail="/website_airproof/static/src/img/wbuilder/s_airproof_snippet.svg">
480-
<keywords>Snippet</keywords>
481-
</t>
482-
</div>
483-
</div>
484-
</t>
485-
</xpath>
484+
<template id="snippets" inherit_id="website.snippets" name="Airproof - Snippets">
485+
<!-- Create the group -->
486+
<xpath expr="//snippets[@id='snippet_groups']/*[1]" position="before">
487+
<t snippet-group="airproof" t-snippet="website.s_snippet_group" string="Airproof" t-thumbnail="/website_airproof/static/src/img/wbuilder/s_airproof_group_thumbnail.svg"/>
488+
</xpath>
486489
</template>
487490
488491
.. list-table::
@@ -492,13 +495,76 @@ page, directly from the edit panel.
492495

493496
* - Attribute
494497
- Description
498+
* - snippet-group
499+
- ID of the group
495500
* - t-snippet
496-
- The template to use
501+
- Inherited template ID
502+
* - string
503+
- Group name displayed to the users
497504
* - t-thumbnail
498-
- The path to the snippet thumbnail
505+
- The path to the thumbnail of the group
506+
507+
3. Snippet addition
508+
~~~~~~~~~~~~~~~~~~~
509+
510+
Then add the custom snippet into the `<snippets id="snippet_structure">` which contains
511+
all existing ones on the same level. The Website Builder will split them automatically into
512+
categories by reading the `group` attribute on the `<t t-snippet="">`
513+
514+
.. code-block:: xml
515+
:caption: ``/website_airproof/views/snippets/options.xml``
516+
:emphasize-lines: 7-12
517+
518+
<template id="snippets" inherit_id="website.snippets" name="Airproof - Snippets">
519+
<!-- Create the group -->
520+
<xpath expr="//snippets[@id='snippet_groups']/*[1]" position="before">
521+
<t snippet-group="airproof" t-snippet="website.s_snippet_group" string="Airproof" t-thumbnail="/website_airproof/static/src/img/wbuilder/s_airproof_group_thumbnail.svg"/>
522+
</xpath>
523+
524+
<!-- Add the custom snippet to the group -->
525+
<xpath expr="//snippets[@id='snippet_structure']/*[1]" position="before">
526+
<t t-snippet="website_airproof.s_airproof_snippet" string="Custom snippet" group="airproof">
527+
<keywords>Snippet</keywords>
528+
</t>
529+
</xpath>
530+
</template>
531+
532+
.. list-table::
533+
:header-rows: 1
534+
:stub-columns: 1
535+
:widths: 20 80
536+
537+
* - Attribute
538+
- Description
539+
* - t-snippet
540+
- The snippet template to use
541+
* - group
542+
- The group in which the snippet is added.
499543
* - <keywords>
500544
- Keywords entered by the user in the search field in the Snippets panel
501545

546+
Inner content snippet
547+
~~~~~~~~~~~~~~~~~~~~~
548+
549+
To make a custom snippet appearing in the :guilabel:`Inner content` list, add it to the `snippet_content`
550+
instead:
551+
552+
.. code-block:: xml
553+
:caption: ``/website_airproof/views/snippets/options.xml``
554+
555+
<template id="snippets" inherit_id="website.snippets" name="Airproof - Snippets">
556+
<!-- Add the custom snippet to the group -->
557+
<xpath expr="//snippets[@id='snippet_content']/*[1]" position="before">
558+
<t t-snippet="website_airproof.s_airproof_snippet" string="Custom snippet" t-thumbnail="/website_airproof/static/src/img/wbuilder/s_airproof_snippet.svg" />
559+
</xpath>
560+
</template>
561+
562+
.. important::
563+
- Don't forget to add a `t-thumbnail` and remove the `group` attribute as this kind of building
564+
blocks is directly available in the right options panel of the Website Builder.
565+
- Don't forget to :ref:`add the snippet to the list of all available "Inner content" snippets
566+
<website_themes/building_blocks/custom/options/inner_content>`.
567+
502568
.. _website_themes/building_blocks/custom/options:
503569

504570
Options
@@ -508,7 +574,7 @@ Options allow users to edit a snippet's appearance/behavior using the Website Bu
508574
snippet options easily and automatically add them to the Website Builder.
509575

510576
.. seealso::
511-
`Standard snippet options <https://github.com/odoo/odoo/blob/ccb78f7af2a4413836a969ff8009dc3df6c2df33/addons/website/views/snippets/snippets.xml>`_
577+
`Standard snippet options <https://github.com/odoo/odoo/blob/247f28fdec788c7eb7c4288db29b931c73a23757/addons/website/views/snippets/snippets.xml>`_
512578

513579
.. _website_themes/building_blocks/custom/options/template:
514580

@@ -552,6 +618,8 @@ Then insert the different available options:
552618
</xpath>
553619
</template>
554620
621+
.. _website_themes/building_blocks/custom/options/inner_content:
622+
555623
**Inner content**
556624

557625
Make a custom snippet "inner content" (droppable in an other building block) by extending the
@@ -570,7 +638,7 @@ inner content building blocks:
570638
571639
.. seealso::
572640

573-
`Standard "inner content" snippets declaration on Odoo's GitHub repository <https://github.com/odoo/odoo/blob/f922f09b83c68dff36c064d20709a6e6ba4541dc/addons/website/views/snippets/snippets.xml#L720>`_
641+
`Standard "inner content" snippets declaration on Odoo's GitHub repository <https://github.com/odoo/odoo/blob/cc05d9d50ac668eaa26363e1127f914897a4b125/addons/website/views/snippets/snippets.xml#L988>`_
574642

575643
.. _website_themes/building_blocks/custom/options/binding:
576644

@@ -949,9 +1017,9 @@ There are also built-in methods directly linked to events the Website Builder li
9491017

9501018
.. seealso::
9511019
- `Web Editor - JavaScript methods related to snippet options on GitHub
952-
<https://github.com/odoo/odoo/blob/380c9153b5fa9a0ea6d7ae485ef52a16ae999eda/addons/web_editor/static/src/js/editor/snippets.options.js#L3247>`_
953-
- `XML templates of the different snippets
954-
<https://github.com/odoo/odoo/blob/ccb78f7af2a4413836a969ff8009dc3df6c2df33/addons/website/views/snippets/snippets.xml>`_
1020+
<https://github.com/odoo/odoo/blob/cc05d9d50ac668eaa26363e1127f914897a4b125/addons/web_editor/static/src/js/editor/snippets.options.js#L3512>`_
1021+
- `XML templates of the different standard snippets
1022+
<https://github.com/odoo/odoo/blob/cc05d9d50ac668eaa26363e1127f914897a4b125/addons/website/views/snippets/snippets.xml>`_
9551023

9561024
.. _website_themes/building_blocks/custom/options/methods/custom:
9571025

0 commit comments

Comments
 (0)