{{ liquidContext }} object

This Liquid object is globally accessible in every liquid template or layout and outputs a combination of the {{this}} and {{request}} Liquid objects as well as any Liquid variables available to the layout it is placed in.

{{ liquidContext }}

Below is a live example of the {{liquidContext}} output for this very documentation article, where a Liquid variable called sampleVar has been assigned in the content.
You'll notice both the request and this data collections are output along with the sampleVar variable that was included in this articles content.

The main purpose of this Liquid object is to assist with easier access to Liquid data while developing your site. See further below for examples of accessing this data during development.

{
    "empty": "",
    "blank": "",
    "siteinformation": {},
    "si": {},
    "this": {
        "Id": 2072,
        "Url": "/sample-page",
        "ParentId": -1,
        "LastUpdatedDate": "2020-06-17T00:38:29",
        "Name": "Sample Page",
        "UrlSlug": "sample-page",
        "Enabled": true,
        "ReleaseDate": "2020-06-16T00:00:00",
        "ExpiryDate": "2099-12-11T13:00:00",
        "Weighting": 0,
        "Description": "HTML Page content here...",
        "ItemTags": "",
        "Author_Name": "",
        "Author_Url": "",
        "Author": "",
        "SEOTitle": "",
        "MetaTitle": "",
        "MetaDescription": "",
        "ShowPageForSearchEngine": false,
        "CanonicalLink": "",
        "EnableAMP": false,
        "AMPContent": "",
        "CodeEditor": true,
        "ExternalId": 0,
        "SocialMetaTags": "",
        "OpenGraphProperties": "",
        "SeoPriority": "0.5",
        "DisableForSiteSearch": false,
        "CreatedByMemberId": 0,
        "ItemCategories": "",
        "ItemCategoryIdList": "",
        "SKUCode": "",
        "SiteSearchKeywords": "",
        "FtpFullPath": "Content\\Pages\\sample-page.html",
        "ParentName": "",
        "ParentUrl": "",
        "TemplateName": "Inner Template",
        "IsHome": false
    },
    "request": {
        "request_url": {
            "href": "https://sample-site.treepl.co/sample-page",
            "origin": "https://sample-site.treepl.co",
            "protocol": "https",
            "hostname": "sample-site.treepl.co",
            "path": "/sample-page",
            "params": {}
        },
        "cookies": {
            "asp.net_sessionid": "kzbvu1ka2zce40h4mm1y1dxr",
            "nice": "false",
            "__stripe_mid": "94001d58-a321-4316-aeb6-70c88e7d5f0c",
            "current.user.identifier": "6aea8081-01c2-45a6-89fd-f286c368cb65",
            "_ga": "GA1.2.159221980.1591595259",
            "__zlcmid": "ydjCSxxleWI2oV",
            "_gid": "GA1.2.1413351276.1592270113",
            "cartid": "7a3317e3-b812-4611-b49a-c2907c13852f"
        },
        "request_data": {
            "ip": "111.222.333.444",
            "is_mobile": 0,
            "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
            "referrer": ""
        },
        "is_logged": false,
        "currentmember": "",
        "device_type": "Desktop",
        "timezone": {
            "label": "(UTC-06:00) Central Time (US & Canada)",
            "offset": -5.0
        } {
            "pagecontent": < YOUR PAGE CONTENT >
        },
        {
            "<yourCustomCollection/s>": {
                <Collection Data>
            },
            "<yourLiquidVariable/s>": "variable Value"
        }
    }
}

Accessing the Data

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

{{ liquidContext.this.url }}

This would output the value /liquid/liquidcontext-object to the page based on the above data.

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>{{liquidContext}}</pre>

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

You can actually use this method to log any Liquid data to the console, such as a custom collection, for example: <pre>{{myCustomCollection}}</pre>

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({{liquidContext | strip_html}});
</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.



Related Articles

  • Working with Liquid
    Treepl has implemented the full standard Shopify Liquid library. See the External Resources below for...
  • Liquid Filters
    Liquid Filters allow you to modify the output of a Liquid object, whether that's adding something to it, removing something from it, executing a calculation, creating an array, or a wide variety of other powerful functions.
  • {{ this }} object
    This Liquid object is globally accessible in every liquid template or layout and outputs specific...
  • {{ request }} object
    This Liquid object is globally accessible in every liquid template or layout and outputs various...
  • {{ member }} object
    This liquid object will output the Member's details of whom submitted a Form. You can...
  • {{ workflow }} object
    This liquid object will output the Workflow details of a submitted Form. You can use...
  • Part 1: Introduction to Liquid
    This free online course covers every aspect of using the Liquid templating language in Treepl CMS - from the very basics right through to advanced implementations.

    You’re welcome.
  • Part 2: Liquid in Treepl CMS
    In this part of the course we’ll explore how Liquid is implemented in treepl CMS and the overall concepts on using it to harness your website data.
  • Part 3: Using Liquid Filters
    In this part of the course we’ll explore using Liquid Filters to transform and manipulate the display of your Treepl CMS website data.
  • Part 4: Advanced Liquid Tags
  • domain_settings
    This module component retrieves settings associated with the current domain, or optionally from another specified domain configured in the site instance.
  • Migrating from Liquid 1.0 to 2.0
    This article describes differences and possible required actions for migrating from the Liquid rendering engine v1.0 to v2.0.

External Resources

There are currently no external resources available.

Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.


Questions?

We are always happy to help with any questions you may have.
Send us a message at support@treepl.co and we will consult you as soon as possible.