# Functions on variables / Modifier

There is a list of predefined functions available that you can apply on your locales, unit data, variables. This list is common for all themes. If you want to add a function, please a product evolution request.

{% hint style="danger" %}
Do not add extra spaces or things like that, it may break the variable / functions.
{% endhint %}

```markup
<!-- LOCALE -->
__@@My text@@__ -> __@@crypt()|My text@@__

<!-- Variable -->
#$variable|title$# -> #$variable|crypt()-title$#

<!-- Unit item -->
{{item.name}} --> {{crypt(item.name)}}

<!-- Unit loop -->
#$loop|{events}|{a}|$#
    {a.name} -> {crypt(a.name)}
#$/loop|{events}|{a}|$#
```

{% hint style="info" %}
For security reasons, the list of functions available is controlled by Galaxy.\
If you wish to add a new function (for example an existing php function), please do a request for it and add the use case.
{% endhint %}

## base64

Encodes the given string with base64

It can easily be decoded in Javascript with [atob()](https://developer.mozilla.org/en-US/docs/Web/API/atob)

```
#$variable|base64()-my_text$#
```

## crypt - Crypt function

Used to crypt email on front-end side (to avoid form recipients email to be directly in the source code)

For forms recipients, we use the function "`crypt`" to make sure the email is not visible on the website in the source code.

{% code title="" %}

```
#$variable|form_recipients$#

#$variable|crypt()-form_recipients$#
```

{% endcode %}

## format\_date - Format Date function

You can use it like this (inside a loop) : `{format_date(a.start_date,'%h')}`

First arg is the date and second arg is the format of the date. \
In this case "`%h`" stands for "Abbreviated month name".\
You can find all the possible parameters on this page <https://www.php.net/manual/en/function.strftime.php>

```
#$loop|{events}|{a}|$#
     {format_date(a.start_date,'%h')}
#$/loop|{events}|{a}|$#
```

**Example:**\
Start date: 2019-03-01 00:00:00\
Formated start date (`%h`): Mar \
Custom format (if inside a CMS variable) (`%d %h %Y (%d/%m/%Y)`): 01 Mar 2019 (01/03/2019)

{% hint style="danger" %}
Currently it is not possible to use any space inside the format of the date inside the theme.\
So `{format_date(a.start_date,'%d %h')}` will not work
{% endhint %}

## htmlentities - Html entities

same as PHP function (Convert all applicable characters to HTML entities)

## JSON related functions

### json\_encode

*to do*

### json\_no\_quote

*to do*

`'"__@@json_no_quote()|GMS Log in@@__"'` <- Only needed when you have simple quotes + double quotes (like in GP2)

### unit\_to\_json

*to do*\
Example: `{unit_to_json(a,"name|short_description|rate")}` (inside a loop)

## remove\_space - Remove space&#x20;

Currently, we need a dedicated function to remove spaces, it can not be a generic function for "replace".\
**01 02 03** becomes **010203**

```markup
#$variable|remove_space()-text$#
{{remove_space(item.name)}}
```

## resizeimg - Resize Image function

**Only available for unit data**, not cms variable.

{% code title="Example of function resizeimg" %}

```markup
<!-- LOOP SYNTAX -->
#$loop|{room}|{a}| $#
    <!-- original image-->
    <img src="{a.first_photo.url_standard}" alt="{a.first_photo.alt}">

    <!-- resize img -->
    <img src="{resizeimg(a.first_photo.url_standard,800)}" alt="{a.first_photo.alt}">
#$/loop|{room}|{a}| $#


<!-- ITEM SYNTAX -->
{{item.first_photo.url_standard}} 

{{resizeimg(item.first_photo.url_standard,800)}} 

```

{% endcode %}

\
round - Round a number
----------------------

round (same as PHP function)

## striptags - Strip tags

strip\_tags (same as PHP function)

## trim - Trim text

same as PHP function `{trim(a.name)}` or `{{trim(item.name)}}`
