I'm using Odoo v16 and I want to use Odoo Official Frontend Docs for v16 as an example,
In the tutorial, we created the Counter OWL Component.
But in the example, they created a controller and initiated the whole OWL stack from the ground (owl_playground.assets_playground
asset).
I want to use the component inside an existing frontend page.
assume I want to show the counter on my home page of the website (not a custom page initiated with from a controller and custom template and main.js
)
How can I do that?
What should I do?
Alternatively, it will be good if I can create a website snippet for that counter or any other Odoo component.
You can
mount
your owl-component in any place using a DOM-selector (document.getElementById(...)):Example in Odoo 16 (odoo/addons/mass_mailing/static/src/snippets/s_rating /options.js):
CASE 2 : Emojis in mail (odoo/addons/mail/static/src/js /emojis_dropdown.js)
CASE 3 : Widget to display odoo field (odoo/addons/mrp/static/src/widgets/timer.js)
--------------- OTHER USE CASES IN ODOO 16 --------------
** SNIPPETS Examples from the official source code:** https://github.com/odoo/odoo/blob/16.0/addons/website/views/snippets/snippets.xml Owl-components are so far just used as part of the js bound to an xml-snippet-template
** odoo/addons/website/views/snippets/s_image_gallery.xml (data-target)**:
dynamic part: odoo/addons/website/static/src/snippets/s_image_gallery/000.xml
Options allow users to edit a snippet’s appearance using the Website Builder. You can create snippet options easily and automatically add them to the Website Builder.Options are wrapped in groups. Groups can have properties that define how the included options interact with the user interface. data-selector binds all the options included in the group to a particular element. It can be used in combination with data-target. Example: option on .carousel-item:
odoo/addons/website/static/src/snippets/s_image_gallery /options.js
The Website Builder provides several events you can use to trigger your custom functions. For example, the event "start" occurs when the publisher selects the snippet for the first time in an editing session or when the snippet is drag-and-dropped on the page:
Public Widget to handle visitor interactions: odoo/addons/website/static/src/snippets/s_image_gallery/000.js
Tutorial to create snippets:
https://www.oocademy.com/v15.0/tutorial/introduction-to-owl-115
https://codingdodo.com/realworld-app-with-owl-odoo-web-library-part-1/
https://codingdodo.com/create-field-widget-in-owl-odoo-16/
https://www.odoo.com/documentation/16.0/fr/developer/howtos/website_themes/building_blocks.html
https://www.youtube.com/watch?v=ukDoXJgS6EQ
To get inspiration, you can download free custom module having snippets in the odoo app store: