diff --git a/doc/howtos/theme_tutorial_assets/img/folder.jpg b/doc/howtos/theme_tutorial_assets/img/folder.jpg deleted file mode 100755 index af2acb93d56..00000000000 Binary files a/doc/howtos/theme_tutorial_assets/img/folder.jpg and /dev/null differ diff --git a/doc/howtos/theme_tutorial_assets/img/theme_folder.jpg b/doc/howtos/theme_tutorial_assets/img/theme_folder.jpg new file mode 100755 index 00000000000..066e85c6158 Binary files /dev/null and b/doc/howtos/theme_tutorial_assets/img/theme_folder.jpg differ diff --git a/doc/howtos/themes.rst b/doc/howtos/themes.rst index efa47c48ec1..5cdfd20181e 100644 --- a/doc/howtos/themes.rst +++ b/doc/howtos/themes.rst @@ -4,6 +4,13 @@ Theme Tutorial ===================== +.. warning:: + + This tutorial provides a great overview of what you can do creating an + Odoo theme. It is however incomplete. We are currently working on a new + detailed theme tutorial, come back here soon to unleash the true power of + Odoo themes! + .. rst-class:: lead Odoo celebrates freedom. Freedom for the designer to go further and @@ -18,11 +25,7 @@ An introduction for web designers ================================= If you are a web designer using Odoo for the first time, you are in the right place. -This introduction will outline the basics of Odoo theme creation. - -.. note:: - - Odoo’s team has created a framework that’s powerful and easy to use. There’s no need to know special syntaxes to use this set of tools. +This introduction will outline the basics of Odoo theme creation. Odoo’s team has created a framework that’s powerful and easy to use. From common CMS to Odoo ----------------------- @@ -60,8 +63,8 @@ Odoo default theme structure .. container:: col-sm-8 - Odoo comes with a default theme structure. - It is a very basic “theme” that provides minimal structure and layout. When you create a new theme, you are actually extending this. + Odoo comes with a default website structure. + It is a very basic “theme” that provides minimal structure and layout. When you create a new theme, you are actually **extending** this. Indeed it’s always enabled in your setup and it acts exactly like the CMS’s base structure we mentioned above, except that you don’t have to create or maintain it. It will upgrade automatically within your Odoo installation and, since it is included in the Website Builder module, everything is smoothly integrated by default. @@ -77,10 +80,10 @@ Odoo default theme structure **Main features:** - * Basic layouts for pages, blog and eCommerce + * Basic layouts for pages, blog, eCommerce and much more * Website Builder integration * Basic Snippets - * Automatic Less/Sass compiling + * Automatic Sass compiling * Automatic Js and CSS minification and combination .. container:: col-md-6 @@ -99,10 +102,10 @@ An Odoo theme is not a folder containing HTML or PHP files, it’s a modular fra Using classical web design workflows, you usually code the layout of the entire page. The result of this is a “static” web page. You can update the content, of course, but your client will need you to work on making even basic changes. -Creating themes for Odoo is a total change of perspective. Instead of defining the complete layout for a page, you can create blocks (snippets) at let the user choose where to “drag&drop” them, creating the page layout on their own. +Creating themes for Odoo is a total change of perspective. Instead of defining the complete layout for a page, you can create blocks (snippets) and let the user choose where to “drag&drop” them, creating the page layout on their own. We call this modular design. -Imagine an Odoo theme as a “list” of elements and options that you have to create and style. +Imagine an Odoo theme as a “list” of elements and options that you have to create or extend. As a designer, your goal is to style these elements in order to achieve a wonderful result, regardless of where the end user chooses to place them. Let’s take a tour of our “list” elements: @@ -134,7 +137,7 @@ Let’s take a tour of our “list” elements: Styles - Styles are defined using standard CSS files (or Less/Sass). You can define a style as **default** or **optional**. The default styles are always active in your theme, the optional styles can be enabled or disabled by the user. + Styles are defined using SCSS files (or you can use standard CSS files). You can define a style as **default** or **optional**. The default styles are always active in your theme, the optional styles can be enabled or disabled by the user. .. figure:: theme_tutorial_assets/img/functionalities.jpg :figclass: col-sm-6 @@ -183,24 +186,6 @@ the **Odoo default structure**. In order to do that you can use Keep reading the tutorial to learn to how properly extend it with your own code. -Update your theme ------------------ - -.. container:: row - - .. container:: col-sm-6 - - Since XML files are only loaded when you install the theme, you will have to force reloading every time you make changes on an xml file. - - To do that, click on the Upgrade button in the module’s page. - - .. image:: theme_tutorial_assets/img/restart.png - - .. container:: col-sm-5 - - .. image:: theme_tutorial_assets/img/upgrade_module.png - - Create a theme module ====================== @@ -231,9 +216,9 @@ Odoo’s themes are packaged like modules. Even if you are designing a very simp Use two underscore characters at the beginning and two at the end of odoo and init file names. -The final result should be something like this: +The final result should be like this: -.. image:: theme_tutorial_assets/img/folder.jpg +.. image:: theme_tutorial_assets/img/theme_folder.jpg Edit ``__manifest__.py`` ------------------------ @@ -242,34 +227,32 @@ Open the ``__manifest__.py`` you created and copy/paste the following: .. code-block:: python - { - 'name':'Tutorial theme', - 'description': 'A description for your theme.', - 'version':'1.0', - 'author':'Your name', + { + 'name': 'Tutorial theme', + 'description': 'A description for your theme.', + 'version': '1.0', + 'author': 'Your name', + 'category': 'Theme/Creative', - 'data': [ - ], - 'category': 'Theme/Creative', - 'depends': ['website', 'website_theme_install'], - } + 'depends': ['website', 'website_theme_install'], + 'data': [ + ], + } Replace the first four property’s values with anything you like. These values will be used to identify your new theme in Odoo’s backend. -The ``data`` property will contain the xml files list. Right now it’s empty, but we will add any new files created. - ``category`` defines your module category (always “Theme”) and, after a slash, the subcategory. You can use one subcategory from the Odoo Apps categories list. (https://www.odoo.com/apps/themes) - -``depends`` specifies the modules needed by our theme to work properly. For our tutorial theme, we only need website and website_theme_install to install/update. If you need blogging or eCommerce features as well, you have to add those modules too. +``depends`` specifies the modules needed by our theme to work properly. For our tutorial theme, we only need website and website_theme_install to install/update. +If you need blogging or eCommerce features as well, you have to add those modules too. +If you plan to offer your theme to the majority of users, it is however recommended that you only depend on website and website_theme_install for the base of your theme. You can then create a second theme, which is an extension of the first one and another Odoo feature like the eCommerce. .. code-block:: python - ... - 'depends': ['website', 'website_theme_install', 'website_blog', 'sale'], - ... + 'depends': ['theme_tutorial', 'website_sale'], +The ``data`` property will contain the xml files list. Right now it’s empty, but we will add any new files created. Installing your theme @@ -283,6 +266,15 @@ After that, navigate to the Odoo **Website** module, go to Under **Website** section click the **Pick a Theme** button, then hover over your theme and click **Use this theme**. +Update your theme +----------------- + +Since XML files are only loaded when you install the theme, you will have to force reloading every time you make changes on an xml file. + +To do that, click on the Upgrade button in the theme selection screen. + +.. image:: theme_tutorial_assets/img/restart.png + Structure of an Odoo page ========================= @@ -296,48 +288,216 @@ By default, Odoo provides you with a **Header** and a **Footer** (cross-pages) a .. image:: theme_tutorial_assets/img/page_structure.jpg To inspect the default layout, simply create a new page using the -Website Builder. Click on :menuselection:`Content --> New Page` and +Website Builder. Click on :menuselection:`New --> New Page` and add a page name. Inspect the page using your browser. .. code-block:: html -
-
-
-
+
+
+
+
-Extend the default Header + +Add Styles +========== + +Introduction +------------ + +The most important feature or your theme should be the style it provides. +Odoo includes Bootstrap by default. This means that you can take advantage of all Bootstrap styles and layout functionalities out of the box. + +Of course Bootstrap is not enough if you want to provide a unique design. The following steps will guide you through how to add custom styles to your theme. +The final result won't be pretty, but will provide you with enough information to build upon on your own. + +Let’s start by creating an empty file called **style.scss** and place it in a folder called **scss** in your static folder. +Let's add an example rule which adds a top border on the footer. Copy and paste it, then save the file. + +.. code-block:: scss + + footer { + border-top: 5px solid theme-color('primary'); + } + +Our file is ready but it is not included in our theme yet. + +Let’s navigate to the view folder and create an XML file called *assets.xml*. +Add the default Odoo xml markup as seen before then copy/paste the following +code between the Odoo tags. Remember to replace ``theme_tutorial`` with your +theme’s main folder name. + +.. code-block:: xml + + + +We just created a template specifying our scss file. As you can see, +our template has a special attribute called ``inherit_id``. This +attribute tells Odoo that our template is referring to another one in +order to operate. + +In this case, we are referring to ``assets_frontend`` template, +located in the ``website`` module. ``assets_frontend`` specifies the +list of assets loaded by the website builder and our goal is to add +our scss file to this list. + +This can be achieved using xpath with the attributes +``expr="link[last()]"`` and ``position="after"``, which means "*take my +style file and place it after the last link in the list of +assets*". + +Placing it after the last one, we ensure that our file will +be loaded at the end and takes priority. + +Finally add **assets.xml** in your **__manifest__.py** file in the data section. + +Update your theme. + +.. image:: theme_tutorial_assets/img/restart.png + + +Our scss file is now included in our theme, it will be automatically compiled, minified and combined with all Odoo’s assets. + +You can now see the beautiful footer border on the website. + + +Advanced tips for styling ------------------------- +In the introduction, we saw how to add a basic file of CSS rules into the +system to extend the website. This is actually the last step you should need to +add style to your theme. + +The Odoo website builder already allows the user to create pages by adding a +large variety of default well-designed blocks. It also allows a large set of +customization possibilities. What may not be straightforward for the user is to +combine all of those options to make something really beautiful. This is where +your theme can shine. First try to construct the spirit of your theme by +enabling a nice set of Odoo default options. This also allows you to ensure two +things: + +- You do not re-invent something which already exists. If Odoo provides an + option to have a border on the footer, don't recode it yourself. Enable it, + then extend it if needed. + +- You ensure that the user can still use all of Odoo features with your theme. + Again, if Odoo provides an option to have a border on the footer and that you + recode it yourself, you may break the default option or make it useless, + making the user have a bad experience. Your option might also not work as well + with all the other Odoo features relying on it. + +So here are the steps to create a robust and consistent style for your theme: + +\(1) Set the values for Odoo-provided SCSS variables + +Odoo declares many CSS rules, most being entirely customizable by overridding +the related SCSS variables. First, create a new file called primary_variables.scss +and add it the same way as the style.scss file. The only difference it that +you won't add it in the ``assets_frontend`` template but in the ``_assets_primary_variables`` +template. + +.. code-block:: xml + + + + +.. important:: + + That file must only contain definition and overrides of SCSS variables and + mixins. + +Add those: + +.. code-block:: scss + + $o-color-palettes: ( + ( + 'o-color-1': #85AFA8, + 'o-color-2': #7E566B, + 'o-color-3': #85909A, + 'o-color-4': #969397, + 'o-color-5': #422335, + ), + ( + 'o-color-1': #54787D, + 'o-color-2': #6B9997, + 'o-color-3': #615145, + 'o-color-4': #C6CCA5, + 'o-color-5': #412342, + ), + ); + +This defines two color palettes for the user to choose from. Odoo relies +on five named colors to be used by the website builder. By defining those in +your theme, you ensure a consistent colored Odoo theme. Starting with Odoo 14.0, +a lot more variable are there for you to customize. + +.. note:: + + All variables defined through those "palettes" SCSS maps can later be + customized by the users themselves. + +\(2) Set the values for Bootstrap variables that Odoo do not surcharge + +If Odoo does not provide the variable you are looking for, then try to find a +Bootstrap variable which allows it. Indeed all Odoo layouts respect Bootstrap +structures and use Bootstrap components or extensions of them. So if you +customize a bootstrap variable, you add a generic style for the whole user +website. + +Bootstrap values **must** not be overridden in the primary_variables.scss file but +in another dedicated file, extending the ``_assets_frontend_helpers`` template. + +.. code-block:: xml + + + +With for example: + +.. code-block:: scss + + $dropdown-min-width: 200px; + +.. important:: + + Make sure to not override Bootstrap variables which depend on Odoo variables + of step (1). Otherwise, you might break the possibility for the user to + customize them using the Odoo website builder. + +\(3) Add your own CSS rules as seen in the introduction + +You may also want to design your snippet first, as we will see in a later +section of this tutorial. + + +Extend Odoo Layout +================== + By default, Odoo header contains a responsive navigation menu and the company’s logo. You can easily add new elements or style the existing one. To do so, create a **layout.xml** file in your **views** folder and add the default Odoo xml markup. -.. code-block:: xml - - - - - - - - -Create a new template into the ```` tag, copy-pasting the following -code. +Then copy-pasting the following code. .. code-block:: xml - -