{{ this }} object

This Liquid object is globally accessible in every liquid template or layout and outputs specific data relating to the item being render.

{{ this }}

For example, if {{this}} is placed in a Page content area it will render the liquid data of that page. Likewise if placed in a Module content field, it will render the liquid data available for the specific module item being viewed.

Below is a live example of the {{this}} output for this very documentation article.

{
  "Id": 2324,
  "Url": "/liquid/this-object",
  "ParentId": 1881,
  "LastUpdatedDate": "2020-09-22T00:00:19",
  "Name": "{{ this }} object",
  "UrlSlug": "this-object",
  "Enabled": true,
  "ReleaseDate": "2018-08-04T00:00:00",
  "ExpiryDate": "2099-11-29T00:00:00",
  "Weighting": 985,
  "Description": "<p>This Liquid object is globally accessible in every liquid template or layout and outputs specific data relating to the item being render.</p>\r\n\r\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"liquid\" %}\r\n<p>For example, if <code>{{this}}</code> is placed in a Page content area it will render the liquid data of that page. Likewise if placed in a Module content field, it will render the liquid data available for the specific module item being viewed.</p>\r\n\r\n<p>Below is a live example of the <code>{{this}}</code> output for this very documentation article.</p>\r\n\r\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{this}}\", lang: \"json\" %}\r\n\r\n{% component type: \"snippet\", alias: \"section_accessing_data\" %}\r\n<p>As an example of rendering a desired value to the page you could use the following Liquid:</p>\r\n\r\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"liquid\" %}\r\n\r\n<p>This would output the value <code>/liquid/this-object</code> to the page based on the above data.</p>\r\n\r\n{% component type: \"snippet\", alias: \"section_viewing_data_while_developing\", object: \"this\", filter: \" | strip_html\" %}\r\n</section>\r\n\r\n\r\n",
  "ItemTags": [
  "Liquid Usage"
],
  "Author_Name": "",
  "Author_Url": "",
  "Author": "",
  "SEOTitle": "",
  "MetaTitle": "",
  "MetaDescription": "",
  "ShowPageForSearchEngine": true,
  "CanonicalLink": "",
  "EnableAMP": false,
  "AMPContent": "",
  "CodeEditor": true,
  "ExternalId": 0,
  "SocialMetaTags": "",
  "OpenGraphProperties": {
  "title": "",
  "type": "",
  "url": "",
  "locale": "",
  "image": ""
},
  "DisableForSiteSearch": false,
  "SeoPriority": "",
  "CreatedByMemberId": 0,
  "ItemCategories": [
  "Sample Category"
],
  "ItemCategoryIdList": [
  "3"
],
  "SKUCode": "",
  "SiteSearchKeywords": "",
  "Active": true,
  "IgnoreUpdates": true,
  "UpdateNotes": "",
  "UpdatesLog": "",
  "ExternalResources": "",
  "AdditionalRelatedArticle_Name": "",
  "AdditionalRelatedArticle_Url": "",
  "AdditionalRelatedArticle": "",
  "AdditionalRelatedArticle2_Name": "",
  "AdditionalRelatedArticle2_Url": "",
  "AdditionalRelatedArticle2": "",
  "Authors": "2418",
  "Module_ID": 1870,
  "Module_Alias": "DocumentationPost",
  "ParentName": "Liquid Objects & Usage",
  "ParentUrl": "/liquid",
  "TemplateName": "Docs Template",
  "IsHome": false
}

Accessing the Data

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

{{ this.url }}

This would output the value /liquid/this-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>{{this}}</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({{this | 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.
  • {{ request }} object
    This Liquid object is globally accessible in every liquid template or layout and outputs various...
  • {{ liquidContext }} object
    This Liquid object is globally accessible in every liquid template or layout and outputs a...
  • {{ siteinformation }}
    This liquid object will output any custom configure Site Information data (found in the Admin's main menu under 'Settings' > 'Site Information').
  • {{ 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.
  • json
    This component parses JSON data for use in Liquid, either from a remote source, a local file, or string.
  • 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.
Visit the Treepl Forum for community support and to search previously asked questions or send us a message at support@treepl.co and we will consult you as soon as possible.