TEMPLATE RULES

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

Template rules allow you to build flexible templates containing rules, which determine which parts of the template are shown, based on what Global Data is available when the site is created.

When you build a template in the editor, you can define a rule, or 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.

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.

Graphic describing relation between Global Data, Template and Generated Site

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.

Screenshot of Edit Button Module Menu Screenshot of Edit Row Menu Screenshot of Page Settings Menu

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.

Image showcasing different headers with different template rules dependent on conversion goal

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:

  • A Global Data element exists or not (e.g. a company logo or short description)
  • A number of Global Data elements (from a collective) exists (e.g. more than 3 images in a gallery)
  • The value of a Global Data element matches something (e.g. country code is US)

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
andcompany_name,phonecompany_name,!phone 
orcompany_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=emailcountry_code=US

6. Template Rules Elements

All Global Data elements can effect the template rules.


Static Elements

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:

logo
cover
company_name
company_name_branding
street
zip
city
state
country
long

lat
phone
fax
email
org_number
description_short
description_long
start_date
mission
custom tags*


Value Based

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:

country_code
timezone
conversion_goal


Countable Elements

There are also countable elements within Global Data, which are listed below:

image
review
offer
video
download
website
paymentMethod
list
priceList
openingHour
socialMedia

Images for galleries or image modules
Reviews and testimonials
Special offers and deals
Available videos
Documents and downloads for link and download
A list of external websites
A list of payment methods
Generic list
Price list sections
=1 if there are opening hours; =0 if there are no opening hours.
A list of social media links,


*Custom tags: 

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:

Screenshot of Edit Row Menu with a Custom Tag example

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. 

GIF of the effects of rules when previewing the site

8. Examples of Valid Entries

emailOnly show if email is populated
video>3Only show if there are more than 3 videos in Global Data
review<5Only show if there are less than 5 reviews
long,image>0Only show if long is populated AND there is at least 1 image
download=4|website=4Only show if there are exactly 4 downloads OR 4 websites
website<2|company_nameOnly show if there are more than 2 websites OR company_name is populated
!emailShow 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.

Screenshot of Edit Row Menu with focus on Language Page Rules

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; 

Screenshot of Edit Button Module menu with focus on Custom CSS Class

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.

Image describing the relation between flattened, un-flattened, trial and paid site.