# Template engine for logic

The system uses the templating language [RainTPL](https://github.com/feulf/raintpl3/wiki/Documentation-for-web-designers).

It allows to do conditions (if / else / elseif) and allows your to add flexibility.

```markup
<div class="hero">
    {if=" '#$variable|subtitle$#' != '' "}
        <h1 class="hero__title h1">#$variable|title$#</h1>
        <p class="hero__subtitle h2">#$variable|subtitle$#</p>
    {else}
      <p class="hero__breadcrumb">#$function|breadcrumb$#</p>
      <h1 class="hero__title h1">#$variable|title$#</h1>
    {/if}
</div>
```

Example in a hero block: if the variable “subtitle” is not empty in the backoffice, we display the subtitle, else we show the breadcrumb.

### &#x20;Rendering (advanced)

The rendering of the page will first&#x20;

* replace CMS variables
* replace unit content
* then at the very end, RainTPL applies the conditions (`if / else if/ else`)

Because of this, on a block that loads conditionally unit loops, it can cause performance issue on the platform.

Example of syntax that can cause performances issues:

```markup
{if=" '#$variable|module-type$#' == 'room' "}
    #$loop|{room}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{room}|{a}| $#
{elseif=" '#$variable|module-type$#' == 'offer' "}
    #$loop|{offer}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{offer}|{a}| $#
{elseif=" '#$variable|module-type$#' == 'hotel' "}
    #$loop|{hotel}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{hotel}|{a}| $#
{else}
    <p>Wrong module</p>
{/if}
```

Here, Galaxy will get unit data for rooms, offers, hotels. Then RainTPL will compile the template with the conditions.

If the website has a lot of rooms, offer, hotel, etc.. it will be slow for 2 different reasons:

* long time to get the unit data
* then, very large template for RainTPL to compile

{% hint style="info" %}
For this specific case, there is a new syntax. These special "start-if" will be done **before adding the unit content**. This way, only the loop you need will be loaded, and not the others.
{% endhint %}

```markup
#$start-if|#$variable|module-type$#|==|room$#
    #$loop|{room}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{room}|{a}| $#
#$else-if|#$variable|module-type$#|==|offer$#
    #$loop|{offer}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{offer}|{a}| $#
#$else-if|#$variable|module-type$#|==|hotel$#
    #$loop|{hotel}|{a}| $#
        <div>{a.name}</div>
    #$/loop|{hotel}|{a}| $#
#$else$#
    <p>Wrong module</p>
#$/end-if|#$variable|module-type$#|==|room$#
```

Syntax details: it checks that `#$variable|module-type$#` == `room`

```markup
#$start-if|#$variable|module-type$#|==|room$#
#$/end-if|#$variable|module-type$#|==|room$#
```
