Template rules are a set of conditional rules for templates that allow you to define parts of a template used in a site, dependent on the available Global Data.
1. WHAT ARE TEMPLATE RULES
2. What can the rules be added to
Template rules can be added to modules, rows and pages. Rules can only be added when creating a template, not when creating a site. Below you can see a number of rules being applied to a button module, a row and a page.
3. How to Add the Rules?
You will need to create a new template in RAI (or via the API if relevant), or copy one of Mono's Base Templates (from global to your local account) to start with. This is no different to creating or copying a new template for any other purpose. Read all about creating templates in RAI here!
When you open your template in the editor, you will see the Template Rules tab on the module, row and page panels. All you must do now is build all your options/variations in the same way you would with a normal template in the editor; except now it is possible to create different variations depending on your Global Data availability. Add your template rules to the rows, modules and pages you wish to influence or change according to the presence of data.
For example, the image below represents four different headers which will be prompted by four different scenarios: 1. Conversion goal is set to deal; 2. Conversion goal is set do email; 3. Conversion goal is set to phone; 4. Conversion goal is not set to any of the previously mentioned options.
4. What can the Template Rules be based on?
The availability of Global Data is what you will base your rules on. That means whether:
You can also specify "and" and "or" rules to string together a set of template rules. However, keep in mind that it is not possible to combine "and" (the comma) and "or" (the pipe) rules on the same rule. You may only use all "and" rules or all "or" rules - not both together.
5. Rule Syntax
The syntax of the rules is described below:
|If [x] exists:||company_name|
|If [x] doesn't exist AKA "not"||!company_name|
|If there are more than 0 of [x]||image>0|
|If there are less than 2 of [x]||image<2|
|If [x] equal [y] (a value from [x])||conversion_goal=email||country_code=US|
6. Template Rules Elements
All Global Data elements can effect the template rules.
The static, singular elements use the name of their tag, which you can find next to the element in the Global Data system. These are listed below:
The value based, singular elements also use the name of their tag, which you can find next to the element in the Global Data system. These are listed below:
There are also countable elements within Global Data, which are listed below:
Images for galleries or image modules
Reviews and testimonials
Special offers and deals
Documents and downloads for link and download
A list of external websites
A list of payment methods
Price list sections
=1 if there are opening hours; =0 if there are no opening hours.
A list of social media links,
Apart from the existing Global Data fields, it is also possible to include rules on custom tags. Custom tags allow you to customize the global content, adapting and supporting it to your personal needs. Read all about Custom tags here!
For example, if you were to add a specific custom tag on, let´s say, a CEO quote, you could add a template rule on a row that would dictate that the row should be displayed if there is content on the CEO quote tag; this template rule would look like:
7. PREVIEW THE EFFECTS OF TEMPLATE RULES
You can easily preview the effects of the rules by adding the relevant global data to your template and opening the preview.
8. Examples of Valid Entries
|Only show if email is populated|
|video>3||Only show if there are more than 3 videos in Global Data|
|review<5||Only show if there are less than 5 reviews|
|long,image>0||Only show if long is populated AND there is at least 1 image|
|download=4|website=4||Only show if there are exactly 4 downloads OR 4 websites|
|website<2|company_name||Only show if there are more than 2 websites OR company_name is populated|
|Show this row if the email Global Data isn't populated|
9. Language Page Rules
It is possible to show elements based on whether the pages they exist on are present in a particular language or not.
For example, if you have template rules (e.g. on company_name]) that you only want to appear on the page within the Danish language version of your website, then you can specify "da" in the "Only Show on Pages with these Languages" field. Languages can be strung together with "and" (the comma) or "or" (the pipe) characters too.
10. CUstom css classES
It is also possible to add Custom CSS Classes on different modules, columns and rows. This allows you to create specific design features on a template, so that they are easily applicable to all sites based upon that template. You can then define your custom CSS under Global Styling;
11. Templates vs Sites
As previously mentioned, you can only set your Template Rules when building a template. Once you apply that template to a site, you won't be able to edit the rules but they will still be active; this means that changes on the site's Global Data will still impact the rules and affect the design and content of your site. This will be the scenario until an API-call to "flatten" the site is made, in which case the rules are stripped when any change is done on the site.