Template Rules are a set of conditional rules that allow you to build flexible templates. Dependent on the available Global Data, these rules define which parts of a template are used on a site.
When you build a template in the editor, you can define a rule, or a set of rules on various elements. When Global Data is used to populate parts of the site, these rules detect which pieces of Global Data are available, and modify the site accordingly.
Example of a Template Rule
For example, if a company logo is added to the Global Data, then a row could be set to display the company logo, phone number and short company description. If a logo is not available in Global Data, but the company name is available, a template rule could determine that a different row is used instead, displaying company name, short description and phone number.
Where can Template Rules be added to?
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!
Template Rules can be added to
Template Rules can only be added when creating a template
Template Rules are part of the template creation process and can only be added when creating a template. Template rules cannot be added when creating a site. Read this article to learn more about how to modify templates in your local library.
Templates vs Sites
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.
How to add Template Rules
When you open your template in the editor, hover the rows, modules and pages you wish to influence and select Template Rules in the dropdown menu. You can now create different variations depending on the available Global Data information. Add your rules in the field Depends on Global Data and click Save.
Below are examples of template rules being applied to a button module, a row and a page:
- Template Rule applied to a Button module: Here you can see a template rule added to a button module. The rule states that the button will show the phone number in case the conversion goal in Global Data is set to "phone".
- Template Rule applied to a Row: Here you can see a template rule applied to a row. The rule states that this row will not show the company logo if the conversion goal in Global Data is set to "phone".
- Template Rule applied to Page Settings: Here you can see an example of a Template Rule being added to Page Settings. This example of a template rule states that once any image has been uploaded on Global Data, this page will show the image. If no image is uploaded under Global Data, no picture will be added to this site.
Example of four different headers which will be prompted by four different scenarios:
- Conversion goal is set to deal
- Conversion goal is set to email
- Conversion goal is set to phone
- Conversion goal is set to any of the previously mentioned options
How do Template Rules look like?
Template Rules are based on what Global Data is available to the site. There are three main options in general:
- Whether or not a Global Data element exists or not (e.g. a company logo or short description)
- The number of existing Global Data elements (from a collective; e.g. more than 3 images in a gallery)
- Whether or not the value of a Global Data element matches something (e.g. country code is US)
You can 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. The syntax of the rules is described below:
- If [x] exists: company_name
- If [x] doesn't exist AKA "not": !company_name
- and: company_name,phone company_name,!phone
- or: company_name|phone
- 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
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
Value based Elements
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:
- image Images for galleries or image modules
- review Reviews and testimonials
- offer Special offers and deals
- video Available videos
- download Documents and downloads for link and download
- website A list of external websites
- paymentMethod A list of payment methods
- list Generic list
- priceList Price list sections
- openingHour =1 if there are opening hours; =0 if there are no opening hours.
- socialMedia 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!
Example of a custom tag applied in template rules
For example, you created a specific custom tag on a CEO quote. You could add a template rule on a row to display the row if there is content on the CEO quote tag in Global Data. Such a template rule would look like this:
Examples of valid entries
- email 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
- 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
- !email Show this row if the email Global Data isn't populated
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.
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 in 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.
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 class under Global Design.