Request, headers, query/post params, site, and automatic_markup objects available while rendering.
These objects describe the current HTTP request and the site while a template renders.
{{ request }} is the reserved root-scope request. {{ headers }}, {{ query_params }}, and {{ post_params }} are also available as request.headers, request.query_params, and request.post_params. {{ site }} is the current site and is the same on every page. {{ automatic_markup }} is the reserved root-scope object for title, meta tags, scripts, and styles the CMS will inject after render; Page Metadata documents that object with the methods that change it.
How to branch on query and POST data is in Working with the Request. {% set_header %} and other response methods are under HTTP Response. Cookies are under Identity & Access.
{{ request }}
The request object is available on every page, and contains information regarding the HTTP request that may be useful for serving and rendering the page.
The full date that the server began processing the request. Using this property prevents the page from being fast-cached, so it is preferable to use the other date-related properties on the request if possible
Will be true if the current request is suspected to be by a bot. Note that this uses a simple method of checking the user agent which is easy for bots to fake, so this should not be used as a definitive test
Object containing all of the cookies for the current request. Note that this is a "live" object that may be modified by the {% set_cookie %} and {% unset_cookie %} methods
ExampleGet request parameters and fetch blog_posts with pagination and tag filterRead page and tag from query params, then fetch blog_posts with limit and sort.
Liquid
{%- assign var postsPerPage = 10 -%}
{%- assign pageParam = 1 -%}
<!-- Did a page param get passed in the url? -->
{%- if request.query_params['page'] -%}
{%- assign pageParam = request.query_params['page'] | to_int -%}
{%- endif -%}
<!-- Did a tag param get passed in the url? -->
{%- if request.query_params['tag'] and request.query_params['tag'] != "" -%}
{%- assign tagFilter = request.query_params['tag'] | url_decode | downcase -%}
{%- endif -%}
{%- blog_posts assign posts = blog:"The Kitchen Essentials" tag:tagFilter limit:postsPerPage page:pageParam sort_by:"post_date" sort_direction:"desc" -%}
{%- for post in posts -%}
{{-post.title-}}
{%- endfor -%}
ExampleLoop over POST parametersIterate over request.post_params (e.g. form fields) to list or process each parameter.
Liquid
<h4>Post Parameters</h4>
<dl>
{%- for param in request.post_params -%}
<dt>{{param}}</dt>
<dd>
{%- if request.post_params.by_name[param] is_list -%}
<ul>
{%- for value in request.post_params.by_name[param] -%}
<li>{{ value }}</li>
{%- endfor -%}
</ul>
{%- else -%}
{{- request.post_params.by_name[param] -}}
{%- endif -%}
</dd>
{%- endfor -%}
</dl>
{{ headers }}
The headers object is available on every page, and contains information regarding the headers sent with the request that may be useful for serving and rendering the page.
JSON representation of the request headers, similar to {{ headers | inspect: 3, false }}
The headers object is copyable, and when copied using {% copy_to_dictionary %} the keys will be the header names and the values will be the corresponding string header values. You may also treat this object as a list containing all of the header names which may be iterated using a {% for %} loop.
ExampleHow to use the request.headers object
Get the origin
Liquid
You are coming from {{ request.headers.origin }}
This example demonstrates how to get and output the origin of the request.
Get a custom header
Liquid
{%- var headername = "X-Custom-Username" -%}
Are you really {{ request.headers[headername] }}?
This example demonstrates how to get and output a custom header from the request.
List all headers
Liquid
<ul>
{%- for header in request.headers -%}
<li><strong>{{ header }}</strong>: {{ request.headers[header] }}</li>
{%- endfor -%}
</ul>
Output an unordered list containing all of the headers and their values from the request.
List all headers with keys
Liquid
<ul>
{%- for header in request.headers.keys -%}
<li><strong>{{ header }}</strong>: {{ request.headers[header] }}</li>
{%- endfor -%}
</ul>
Enumerating request.headers.keys is the same as enumerating request.headers, so this example is functionally identical to the previous example.
{{ query_params }}
Object containing all of the query string parameters for the current page.
A list of all of the query parameters in the order they appear in the URL. Each item in the list is the full query parameter - including both the key and the value. Note that this may include empty and/or duplicate query parameters
by_name
object
An object whose properties match the query parameters in the URL, including query parameters with empty values. If the same query parameter appears multiple times in the URL, the value will be a comma-separated list of all of the values for that key.
You may treat the query_params object as a list containing all of the query parameters which may be iterated using a {% for %} loop. The query_params object is copyable using the {% copy_to_dictionary %} method.
ExampleGet request parameters and fetch blog_posts with pagination and tag filterRead page and tag from query params, then fetch blog_posts with limit and sort.
Liquid
{%- assign var postsPerPage = 10 -%}
{%- assign pageParam = 1 -%}
<!-- Did a page param get passed in the url? -->
{%- if request.query_params['page'] -%}
{%- assign pageParam = request.query_params['page'] | to_int -%}
{%- endif -%}
<!-- Did a tag param get passed in the url? -->
{%- if request.query_params['tag'] and request.query_params['tag'] != "" -%}
{%- assign tagFilter = request.query_params['tag'] | url_decode | downcase -%}
{%- endif -%}
{%- blog_posts assign posts = blog:"The Kitchen Essentials" tag:tagFilter limit:postsPerPage page:pageParam sort_by:"post_date" sort_direction:"desc" -%}
{%- for post in posts -%}
{{-post.title-}}
{%- endfor -%}
ExampleRead and iterate over request.query_paramsAccess URL query parameters via request.query_params: count, length, keys, by_index, and conditions like has_key or contains.
There are 4 distinct query parameters in the URL: alpha, beta, emptyvariable, and animals. Note that the empty query parameter is NOT included in the count.
Liquid
{{ request.query_params.length }}
Output
7
There are total of 7 query parameters in the URL, including one that does not have a value, one that does not have a key or a value, and one that is repeated three times
Liquid
{{ request.query_params.alpha }}
Output
abc
The value of the alpha query parameter is abc
Liquid
{{ request.query_params.emptyvariable }}
The value of the emptyvariable query parameter is empty
Liquid
{{ request.query_params['animals'] }}
Output
cat,dog,fish
The value of the animals query parameter is a comma-separated list of the values: cat, dog, and fish
The query parameter keys can be iterated using a {% for %} loop. Note that this includes keys that do not have values, but does NOT include query parameters that do not have keys.
{{ post_params }}
Object containing all of the HTTP posted parameters from the current request.
An object whose properties match the posted parameters from the request. If the same parameter has multiple values, they will be included as a list of strings rather than simply as a single string, and when treated as a single string the values will be comma-delimited
The posted parameters formatted similar to a query parameter string (ie: as if the post request used a content-type of application/x-www-form-urlencoded)
You may treat the post_params object as a list containing all of the parameters which may be iterated using a {% for %} loop. The post_params object is copyable using the {% copy_to_dictionary %} method.
ExampleLoop over POST parametersIterate over request.post_params (e.g. form fields) to list or process each parameter.
Liquid
<h4>Post Parameters</h4>
<dl>
{%- for param in request.post_params -%}
<dt>{{param}}</dt>
<dd>
{%- if request.post_params.by_name[param] is_list -%}
<ul>
{%- for value in request.post_params.by_name[param] -%}
<li>{{ value }}</li>
{%- endfor -%}
</ul>
{%- else -%}
{{- request.post_params.by_name[param] -}}
{%- endif -%}
</dd>
{%- endfor -%}
</dl>
{{ site }}
The site object is available on every page, and contains information about the current site. This information is the same on every page for the site.
True if "live editing" is enabled for this site. Note that this only indicate whether it is enabled. To know whether or not the edit link will be displayed, use {{ automatic_markup.show_edit_link }} instead
An object containing all of the site-wide settings for the site currently being viewed. You can query the settings directly using {{ site.settings['setting-name'] }} or using the shortcut {{ site.setting-name }}
The site object is copyable, and when copied will copy all of the site settings to the resulting dictionary.
ExampleWorking with specific object propertiesThere are multiple ways to reference properties on most objects. This example demonstrates several patterns for accessing properties on a few different object types.
Reference properties on the user object
Liquid
{%- if user.is_valid -%}
{%- if user.custom_property_name -%}
<p>Custom Property: {{user.custom_property_name}}</p>
{%- endif -%}
{%- if user['custom_property_name_2'] -%}
<p>Custom Property 2: {{user['custom_property_name_2']}}</p>
{%- endif -%}
{%- endif -%}
Reference properties on the client object
Liquid
{%- if client.is_valid -%}
{%- if client.custom_property_name -%}
<p>Custom Property: {{client.custom_property_name}}</p>
{%- endif -%}
{%- if client['custom_property_name_2'] -%}
<p>Custom Property 2: {{client['custom_property_name_2']}}</p>
{%- endif -%}
{%- endif -%}
Reference properties on the session object
Liquid
{%- if session.is_valid -%}
{%- if session.custom_property_name -%}
<p>Custom Property: {{session.custom_property_name}}</p>
{%- endif -%}
{%- if session['custom_property_name_2'] -%}
<p>Custom Property 2: {{session['custom_property_name_2']}}</p>
{%- endif -%}
{%- endif -%}
The automatic_markup object contains information about the data and markup that will be added to the page automatically after it is rendered by the template.
The page title as it is currently configured to be output as part of the automatic markup. Defaults to {{ entity.browser_title }} but may be set to another value using {% set_title %}
The page meta description as it is currently configured to be output as part of the automatic markup. Defaults to {{ entity.meta_description | default:site.default_meta_description }} but may be set to another value using {% set_description %}
The page robots meta information as it is currently configured to be output as part of the automatic markup. Defaults to {{ entity.meta_robots }} but may be set to another value using {% set_robots %}
The page's canonical url meta information as it is currently configured to be output as part of the automatic markup. Defaults to {{ entity.canonical_url }} but may be set to another value using {% set_canonical_url %}
The favicon for the page as it is currently configured to be output as part of the automatic markup. Does NOT have a default value but may be set using {% set_favicon %}
True if the template is currently configured to output automatic markup in the head of the current page. Defaults to true but may be changed using {% toggle_automatic_markup %}
True if the template is currently configured to output automatic markup in the body of the current page. Defaults to true but may be changed using {% toggle_automatic_markup %}
True if the template is currently configured to output extra markup (HTML and javascript) as a result of being loaded through the preview UI in Marketpath CMS
True if the template is currently configured to output the "Edit Page" link to the current page. Note that this depends on a number of factors, the most notable of which are the site configuration and the user being logged in to Marketpath CMS at the same time. Can be changed using {% toggle_automatic_markup %}, but only if the pre-requisites for showing the edit link have been met
The markup that will be output to the end of the head of the current page. This includes the stylesheets and javascript that were added to the header using {% add_stylesheet %} and {% add_javascript %}
The markup that will be output to the end of the body of the current page. This includes the stylesheets and javascript that were added to the body using {% add_stylesheet position:body %} and {% add_javascript position:body %}
The list of stylesheet linked_src objects that should be output to the document body as part of the automatic markup (most styles should be added to the head and not the body except in rare edge-cases)