In this article we are going to explain why the theme.yml file is so important.
But first, please, check out some basic info about .yml. Newbies will find this config validation service quite useful as well: http://www.yamllint.com/.
And here is the table of all PrestaShop pages for your reference, because it is really important to know which page a Page_Identifier corresponds to. You will understand it better while reading further.
Page_identifier | url page | description page |
address | /address | |
addresses | /addresses | |
authentication | /login | Authorization page |
cart | /cart | |
category | /index.php?controller=category | any category page |
cms | /index.php?controller=cms | |
contact | /contact-us | contact page |
discount | /discount | |
guest_tracking | /guest-tracking | |
history | /order-history | |
identity | /identity | |
index | / | homepage |
my_account | /my-account | |
order | /order | |
order_confirmation | /order-confirmation | |
order_detail | /index.php?controller=order-detail | |
order_follow | /order-follow | |
order_login | /order?login=1 | |
order_return | /index.php?controller=order-return | |
order_slip | /credit-slip | |
pagenotfound | /page-not-found | |
password | /password-recovery | |
pdf_invoice | /index.php?controller=pdf-invoice | |
pdf_order_return | /index.php?controller=pdf-order-return | |
pdf_order_slip | /index.php?controller=pdf-order-slip | |
prices_drop | /prices-drop | |
product | /index.php?controller=product | |
register | /login?create_account=1 | |
search | /search | |
sitemap | /sitemap | |
stores | /stores | |
supplier | /supplier |
The file theme.yml is located under the following directory:
/themes/<theme_folder>/config/theme.yml
This file is obligatory for any theme.
Here is also the list of options that must be present in this file:
- name;
- display_name;
- version;
- name;
- compatibility.from;
- available_layouts;
- image_types.cart_default;
- image_types.small_default;
- image_types.medium_default;
- image_types.large_default;
- image_types.home_default;
- image_types.category_default;
- default_layout.
So, let’s start from the beginning.
1. Theme info
name – a theme directory name (an obligatory property).
The directory name should match the theme name. Some examples:
1 2 3 |
name: сlassic name: my-theme # theme name “My Theme” name: belvg-zerro # them name “Belvg Zerro” |
display_name – a theme name (an obligatory property).
version: current theme version, use Semantic Versioning (an obligatory property).
1 2 3 4 |
author: name: "BelVG" # the name of the author or the company which created the theme (an obligatory property), url: "http://module-presta.com" # either company or author's website |
2. Theme settings
All the settings below can be changed through an interface in the theme’s back office interface, and only depend on the theme/shop combination.
When the theme.yml file is parsed by PrestaShop, the ‘theme_settings’ configuration key is copied to a file named settings_n.yml, where ‘n’ is the id of the shop where the theme is installed (settings_123456.yml, for instance).
When the configuration is changed through the back office interface, only the settings_n.yml file is updated – the theme.yml file remains unchanged.
1 2 3 4 5 6 7 8 9 10 11 |
theme_settings: default_layout: layout-full-width #(an obligatory property ) as mentioned earlier, it is the default layout. layouts: # the property describes the page where one or another layout will be used. index: layout-home-page category: layout-left-column best-sales: layout-left-column new-products: layout-left-column prices-drop: layout-left-column contact: layout-left-column # syntax: <page_identifier>:<layout> see the examples below, # the table with the list of page_identifiers is available at the beginning of the article. |
Note what is a PrestaShop layout:
- all layout files are located under /<theme_folder>/layouts/<layout>.tpl
- By default, any layout is defined by the property default_layout
- A description for every <layout>can be added to the property available_layouts (example below)
3. Meta info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
meta: available_layouts: # the description of all <layout> that can be present in the /<theme_folder>/layouts/ folder layout-full-width: # a <layout> identifier (matches the name of the file <layout>.tpl) name: │_________│ Full Width description: No side columns, ideal for distraction-free pages such as product pages. layout-left-column: name: │__│______│ Two Columns, small left column description: Two columns with a small left column layout-right-column: name: │______│__│ Two Columns, small right column description: Two columns with a small right column layout-both-columns: name: │__│____│__│ Three Columns description: One large central column and 2 side columns. compatibility: # the compatibility of your theme with specific versions of PrestaShop from: 1.7.0.0 #(an obligatory property) supported from to: ~ #(an obligatory property) “~” meaning 'all versions' |
4. Asset Management
PrestaShop 1.7 has quite an advanced system of Asset Management. Here is an example of connecting css/js files with the help of theme.yml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
assets: css: product: # only on a product page - id: product-extra-style # connecting path: assets/css/product.css # the .сss file which is located in /themes/<theme_folder>/assets/css/product.css media: all # installing the attribute media=”all” priority: 100 # assigning the priority value 100 to the file js: all: # on any page - id: belvg-super-lib # connecting path: assets/js/belvg-super.js # a .js library which is located under /themes/<theme_folder>/assets/js/belvg-super.js priority: 33 # assigning the priority value 33 to the file position: bottom # outputting at the bottom of the page before the closing tag </body> product: # only on a product page - id: product-custom-lib # connecting path: assets/js/product.js # a .js library which is located under /themes/<theme_folder>/assets/js/product.js priority: 200 # assigning the priority value 200 to the file attribute: async # adding async attribute |
In the table below you get the list of files that can are connected to PrestaShop automatically:
Filename | ID | Priority | Comment |
theme.css | theme-main | 0 | Most (all?) of your theme’s styles. Should be minified. |
rtl.css | theme-rtl | 900 | Loaded only for Right-To-Left language |
custom.css | theme-custom | 1000 | Empty file loaded at the very end to allow user to override some simple style. |
core.js | corejs | 0 | Provided by PrestaShop. Contains Jquery2, dispatches PrestaShop events and holds PrestaShop logic. |
theme.js | theme-main | 50 | Most of your theme’s JavaScript. Should embed libraries required on all pages, and be minified. |
custom.js | theme-custom | 1000 | Empty file loaded at the very end, to allow user to override behavior or add simple script. |
аssets.css – the property includes the list of pages and the list of connected .css files
conditional syntax:
# – comments
| – or
[] – an optional parameter
<name variables> – a variable value
0..9 – enumeration of available values from 0 to 9
1 2 3 4 5 6 7 8 9 10 |
assets: css: <page_identifier>|all: # the list of all identifiers is available at the beginning # of the article, all - for all pages - id: <assets_id> # a unique identifier path: path/to/my.css # the path to the file is taken from the theme folder [priority: <0..999>] # (default: 50), 0 is the highest priority [inline: <true|false>] # (default: false), If true, your style will be printed inside # the <style> tag in your HTML <head>. Use with caution. [media: <all|braille|embossed|handheld|print|projection|screen|speech| tty|tv>] # (default: all) |
аssets.js – the property includes the list of pages and the list of connected .js files
The syntax is quite similar, you just have a few new parameters added there:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
assets: js: <page_identifier>|all: # the list of all identifiers is available at # the beginning of the article, all - for all pages - id: <assets_id> # a unique identifier path: path/to/my-lib.js # the path to the file is taken from the theme folder [priority: <0..999>] # (default: 50), 0 is the highest priority [attribute: <async|defer|none>] # (default: none) Load JavaScript file with the corresponding attribute [position: <head|bottom>] # (default: bottom) JavaScript files should be loaded in the bottom # as much as possible. Remember: core.js is loaded first thing in the # bottom so jQuery won’t be loaded in the <head> part. [inline: <true|false>] # (default: false), If true, your style will be printed # inside <script type="text/javascript"> tags inside your HTML. Use with caution. |
5. Global Settings
5.1 Configuration of PrestaShop
The property global_settings.configuration is responsible for PrestaShop settings, therefore, when installing a new theme the settings will be changed.
Example:
1 2 3 4 5 6 7 |
global_settings: configuration: PS_SEARCH_AJAX: 0 PS_PNG_QUALITY: 8 BLOCKTAGS_NBR: 10 HOME_FEATURED_NBR: 8 BLOCKSPECIALS_SPECIALS_NBR: 8 |
5.2 Modules
modules.to_enable – All modules below are enabled when the theme is enabled (and installed if needed). They are disabled when the theme is disabled.
modules.to_disable – All modules below are disabled when the theme is enabled. They are re-enabled when the theme is disabled.
Example:
1 2 3 4 5 6 7 8 |
global_settings: modules: to_enable: - my-custom-module - yippeeslider to_disable: - homeslider - blockwishlist |
Using hooks you can control the place and output of any specific module on a page and also exclude the pages where that module is not needed. Most significantly, you can also create custom hooks and define the modules that they will connect.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
global_settings: hooks: custom_hooks: # optional, yet for your theme users it might be important to know what this specific hook is responsible for and where it is located. - name: myCustomHook title: myCustomHook description: Add a widget area above the footer modules_to_hook: myCustomHook: - ps_contactinfo # ps_contactinfo is hooked on myCustomHook on all pages displayNav2: - ps_languageselector - ps_currencyselector displayNav1: - ps_contactinfo: except_pages: - contact - history # ps_contactinfo is hooked on displayNav1 on all pages # except "contact" and "history" pages displayHomeTabs: # displayHomeTabs will have whatever is currently hooked to it # kept hooked to it, and ps_emailsubscription will be appended # to the list (or moved to the end if already hooked there). - ~ - ps_emailsubscription displayTop: - ps_mainmenu |
5.3 Image settings
Enabling the theme will remove all the existing image types.
Therefore, themes MUST declare their image types, and what they apply to.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
global_settings: image_types: cart_default: #(an obligatory property) width: 125 height: 125 scope: [products] small_default: #(an obligatory property ) width: 98 height: 98 scope: [products, categories, manufacturers, suppliers] medium_default: #(an obligatory property ) width: 452 height: 452 scope: [products, manufacturers, suppliers] home_default: #(an obligatory property ) width: 255 height: 320 scope: [products] large_default: #(an obligatory property ) width: 800 height: 800 scope: [products, manufacturers, suppliers] category_default: #(an obligatory property ) width: 141 height: 180 scope: [categories] |
5.4 Dependencies
To create a theme we may use various modules, but if you are using some third-party module it should be declared in the list of dependencies which Prestashop will download and install.
Example:
1 2 3 4 5 |
dependencies: modules: - blockreassurance - xx_customsubscription - xx_customslider |
Hi Luk,
You’re welcome, glad it was helpful.
THANK YOU FOR THE YAML SITE I LOST HOURS