.. highlight:: xml
===============
Creating themes
===============
Basic set up
============
Create a basic theme module with :command:`odoo.py scaffold` and the ``theme``
template: from the root odoo folder, use
.. code-block:: console
$ ./odoo.py scaffold -t theme "Dummy Theme" addons
this should create a new folder ``dummy_theme`` in the ``addons`` directory
with the structure:
.. code-block:: text
addons/dummy_theme
|-- __init__.py
|-- __openerp__.py
|-- static
| `-- style
| `-- custom.less
`-- views
|-- options.xml
|-- pages.xml
`-- snippets.xml
``static/styles`` contains your stylesheet(s), ``views`` contains the various
XML files describing the theme and theme features to Odoo.
Static Page
-----------
Creating a new template
'''''''''''''''''''''''
Create a new file :file:`odoo/addons/theme_dummy/views/pages.xml` and open it.
In odoo, a page means a new template. You don't need special skills, simply
copy paste the lines::
Refresh the page and feel the hit.
Editing content on a page
'''''''''''''''''''''''''
You can now add you content! You should always use the Bootstrap structure as
below::
This is Your Content
Isn't amazing to edit everything inline?
Adding new item in the menu
'''''''''''''''''''''''''''
Adding these few more lines will put the new page in your menu::
Congrats! It's online! Now drag and drop some snippets on the page and let's
style!
Pimp Your Theme
---------------
Easy styling with less
''''''''''''''''''''''
In ``odoo/addons/theme_dummy/static`` create a new folder and name it
``style``. In the new folder ``odoo/addons/theme_dummy/static/style`` create a
file and name it ``custom.less``. Open ``custom.less`` in the text editor and
modify these lines as below:
.. code-block:: css
.h1 {
color: #215487;
}
.span {
border: 2px solid black;
background-color: #eee;
}
Refresh the page and feel the hit.
Get the most of the dom
'''''''''''''''''''''''
Right-Click, inspect element. You can go deeper by styling the main layout
container. Here we try with the 'wrapwrap' id.
.. code-block:: css
#wrapwrap {
background-color: #222;
width: 80%;
margin: 0 auto;
}
Easy layout with bootstrap
''''''''''''''''''''''''''
Open :file:`odoo/addons/theme_dummy/views/pages.xml` and add a new section::
Refresh the page and check how it looks.
The background of the alert component is the default Bootstrap primary color.
The two other div your created have no custom styles applied yet. Open
:file:`odoo/addons/theme_dummy/static/style/custom.less` and add these lines:
.. code-block:: css
@brand-primary: #1abc9c;
@color-blue: #3498db;
@color-green: #2ecc71;
.bg-blue { background: @color-blue; }
.bg-green { background: @color-green; }
.h2 { color: white; }
As you see, the default primary has changed and your new colors are shining!
Build Your First Snippet
------------------------
Setting up __openerp__.py
'''''''''''''''''''''''''
Open ``__openerp__.py`` and add a new line as below:
.. code-block:: python
{
'name': 'Dummy Theme',
'description': 'Dummy Theme',
'category': 'Website',
'version': '1.0',
'author': 'OpenERP SA',
'depends': ['website'],
'data': [
'views/snippets.xml',
],
'application': True,
}
In ``odoo/addons/theme_learn/views`` create a new xml file, name it
``snippets.xml`` and open it in a text editor
Add your snippet in the menu
''''''''''''''''''''''''''''
Before typing your html code, you need to locate it in the WEBb. drop-down
menu. In this case, we will add it at the end of the Structure section::
Now open a new div, do not give it any id or classes. It will contain your
snippet::
A thumbnail is also needed to create a more attractive link in the menu. You
can use labels to focus on your themes snippets. Simply add a new div with
the class ``oe_snippet_thumbnail`` and add your thumbnail image (100x79px)::
SNIP IT!
And voila! Your new snippet is now ready to use. Just drag and drop it on your
page to see it in action.
The snippet body
''''''''''''''''
A snippet has to be in a section with the class ``oe_snippet_body`` to work
correctly. As Odoo use the Bootstrap framework, you have use containers and
rows to hold your content. Please refer the the Bootstrap documentation::
SNIP IT!
Inside your fresh new row, add some bootstraped contents::
A great Title
And a great subtitle too
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Adding images to your snippet
'''''''''''''''''''''''''''''
You can easely add images in your snippets simply by setting up css
backgrounds images.
In ``odoo/addons/theme_dummy/static/`` create a new folder and name it
``img``. Put your images there, in sub-folders if needed. Open
:file:`odoo/addons/theme_dummy/static/style/custom.less`, add these lines
.. code-block:: css
@img-01: url("../img/img-boy.png");
.dummy-boy { background-image: @img-01; }
@img-02: url("../img/img-girl.png");
.dummy-girl { background-image: @img-02; }
In :file:`odoo/addons/theme_dummy/views/pages.xml` change the correspondant
lines as below::