Global Variables

CMS variables are scoped only inside their block (or list/page), you can not access them from another block.

Global Variables are shared settings across the whole website. You can access their value from any block, page, header, footer, etc...

Each global variable also has a category (you can create as many as you want), that will allow organizing variables by "goal"

Example 1 - Showing prices

For example, if you want an option to show/hide prices everywhere on the website, you could do:

{if=" '#$global|settings|show-prices$#' "}
    <!-- your code here -->
{/if}

#$global|settings|show-prices$# is a global variable with the key "show-prices" in the category "settings"

  • settings: the category key

  • show-prices: the variable key

Example 2 - Map default zoom

For example, if you want a default zoom for the maps everywhere on the website, you could do:

{if=" '#$global|map|default-zoom$#' "}
    <!-- your code here -->
{/if}

#$global|map|default-zoom$# is a global variable with the key "default-zoom" in the category "map"

  • map: the category key

  • default-zoom: the variable key

The combination of the category and the key creates a unique identifier for your variable (so if you change the category key, it is a new variable)

Edit value in the backoffice

To edit your variable go to your website, sidebar > Settings > Global Variables

The section is still a work in progress:

  • permissions are not defined yet, only some users have access to it

  • you can only "simple" input fields (no switch, etc.)

Not all users have access to the "Global Variables" section

Code

Here is the syntax: #$global|category|variable-key$#

#$global|settings|show-prices$#
<!-- category: settings; key: show-prices -->

#$global|map|default-zoom$#
<!-- category: map; key: show-prices -->

You can create categories, they are defined at the theme level

Edit variable configuration

Read temporary documentation

As it is not yet possible to edit the variable configuration inside Testeur, you have to edit the .data files manually in the file theme/global/{CATEGORY_KEY}/{VARIABLE_KEY}.data

Example:

Let's imagine you have a variable #$global|settings|show-prices$# and #$global|map|default-zoom$#

You need to create 2 files:

theme/global/settings/show-prices.data and theme/global/map/default-zoom.data

Here is an example of the content:

label = "Show lead rate"
type_id = "1"
content = ""
is_edit_visual = "0"
is_translate = "1"
dependance_cms_variable_e_id = ""
dependance_value = ""
variable = "show-lead-rate"
data_type_id = ""
sort = ""

On your side, you can change

  • label = "Show lead rate" the label visible in the backoffice

  • variable = "show-lead-rate" the key of the variable

  • is_translate = "1" if the variable is translatable or not

Last updated