Change Log

  • 09-Nov-2022 | v6.8.0 | Updated 'Site Information' to 'Site Globals' (due to system name change)
  • All new article

Contributors:

Adam Wilson - Logo Pogo

{{ siteglobals }}

This liquid object will output any custom configure Site Information data (found in the Admin's main menu under 'Settings' > 'Site Information').

{{ siteglobals }}

Notice the below data has duplicate values with shorthand names. Likewise the whole Site Globals object can also be access using a shorthand alias:

{{ sg }}

Liquid Output

An example data structure for two Globals Groups defining the site's design elements and site contacts:

{
  "demo_design_elements": {
    "site_logo": "/images/logo.png",
    "sl": "/images/logo.png",
    "primary_color": "#0091EA",
    "pc": "#0091EA"
  },
  "dde": {
    "site_logo": "/images/logo.png",
    "sl": "/images/logo.png",
    "primary_color": "#0091EA",
    "pc": "#0091EA"
  },
  "demo_site_contacts": {
    "phone": "1300 123 123",
    "p": "1300 123 123",
    "email": "info@yourdomain.com",
    "e": "info@yourdomain.com",
    "address": "1 Demo St,\nDemoville, CA, 10000",
    "a": "1 Demo St,\nDemoville, CA, 10000"
  },
  "dsc": {
    "phone": "1300 123 123",
    "p": "1300 123 123",
    "email": "info@yourdomain.com",
    "e": "info@yourdomain.com",
    "address": "1 Demo St,\nDemoville, CA, 10000",
    "a": "1 Demo St,\nDemoville, CA, 10000"
  },
  "config": {
    "dev_mode": "false",
    "dev": "false"
  }
}

Accessing the Data

JSON Output

You can output the full JSON for your component data by referencing the root Liquid object {{this}} in your module’s layouts, or directly on your page, if using the collectionVariable parameter in your component tag.

For example:

{% component type: ... collectionVariable: "myData" %}

You can then render the JSON like so:

{{myData}}

For more details on using this approach, see Part 2 of the free ‘Learning Liquid Course’.

Rendering Property Values

As an example of rendering a desired value to the page you could use the following Liquid:

{{ siteglobals.demo_design_elements.site_logo }}

This would output the value /images/logo.png to the page based on the above example data.

Alternatively, using the shorter aliases, for easier reference, the alias version of the above might look like this:

{{ sg.dde.sl }}

Viewing Data while Developing

It is often desirable to see all the data that is available to you on a page while developing your applications and there are two common techniques for doing this.

1. Rendering JSON to the Page

You can quickly and easily render the full JSON output directly to the page you are working on in order to view all the data and its structure in an easy to read format.
Simply wrap your desired Liquid object in <pre> tags like so; <pre>{{siteglobals}}</pre>

A JSON representation of the available data will be rendered to the page similar to the output examples above.

This of course is a temporary technique as you would not want to leave the JSON data visible on the page.

2. Rendering JSON to the Console

Perhaps a cleaner and more persistent way of viewing this data while in development, is to log the JSON output to your browser's console (in the browser's Developer Tools).

To do this, add some javascript code to your template file (just before the closing </body> tag) like this:

<script>
    console.log({{siteglobals}});
</script>

What this will do is output the JSON data into a structured data tree in your browser's Developer Tools console.

You can actually use this method to log any Liquid data to the console, such as a custom collection, for example:

<script>
    console.log({{myCustomCollection | strip_html}});
</script>

You might notice the Liquid filter | strip_html added here. This is optional, however, in some cases the JSON data will contain HTML code and this can break the Javascript, causing a scripting error.
So, keep in mind that, when using this filter, any fields containing HTML code in your JSON will not actually show the HTML in the console, however, the data is still there and accessible via Liquid when rendering to the page.

Remember to remove this code for production as it could pose a data security risk and it is best practice not to leave console logs in your scripts.