Skip to documentation content

Request Context

Request Context

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.

Properties
Properties of {{ request }} objects
Name Type Description
object_type string Will always be request
is_valid boolean True if the request is for a Marketpath CMS Page. False if it is a 404 page.
domain string The requested domain name
method string The lowercase HTTP method of the current request (eg: "get" or "post")
use_ssl boolean True if the request used the "https" scheme
path string The part of the URL after the domain, including the leading '/' but not including the query string parameters or hash.
query_string string Everything after the '?' character in the URL
query_params {{ query_params }} Object containing all of the query string parameters for the current page
post_params {{ post_params }} Object containing all of the HTTP posted parameters for the current request
url string The full URL of the current request - including the scheme, the domain, the path, and the query string
is_preview boolean True if the request is being served from the preview environment
date {{ time }} 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
year integer The year that the server began processing the request
month integer The month of the year that the server began processing the request (1 through 12)
day integer The day of the month that the server began processing the request (1 through 31)
hour integer The hour that the server began processing the request (0 through 23)
timezone string The name of the current timezone used to display dates (eg: PST or PDT)
timezone_full string The full name of the timezone used to display dates (eg: "America/Indianapolis")
user_agent string The User Agent supplied by the current request
searchterm string Only set if the {% search %} method was used and will contain the searchterm used by the {% search %} method
is_suspected_bot boolean 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
headers {{ headers }} Object containing all of the headers sent with the current request
cookies {{ cookies }} 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
Example Get 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 -%}
Example Loop 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.

Properties
Properties of {{ headers }} objects
Name Type Description
object_type string Will always be headers
is_valid boolean Will always be true
keys list The list of header names sent in the request
count integer The number of header names sent in the request
* string Specific headers may be accessed using {{ request.headers.headername }} or {{ request.headers['header-name'] }}
output string 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.

Example How 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.

Properties
Properties of {{ query_params }} objects
Name Type Description
object_type string Will always be query_params
is_valid boolean Will always be true
by_index list 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.
keys list A list containing all of the unique query parameter names
count integer The number of unique query parameter names in the URL.
length integer The total number of query parameters in the URL, including empty and duplicate query parameters
* string Specific query parameter values may be accessed using {{ request.query_params.parametername }} or {{ request.query_params['parameter-name'] }}
output string The full raw querystring from the request

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.

Example Get 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 -%}
Example Read 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.
Liquid
{{ request.query_params }}
Output
alpha=abc&beta=b&&emptyvariable&animals=cat&animals=dog&animals=fish
Liquid
{{ request.query_params.count }}
Output
4

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

Liquid
{{ request.query_params[1] }}
Output
beta=b

The value of the second query parameter is beta=b

Liquid
{% if request.query_params has_key 'alpha' %}has alpha{% else %}no alpha{% endif %}
Output
has alpha

The alpha query parameter is present in the URL

Liquid
{% if request.query_params contains 'animals=cat' %}cat{% else %}no cat{% endif %}
Output
cat

The animals=cat query parameter is present in the URL. Note that the contains condition checks for both the key AND the value of the query parameter.

Liquid
{%- for param in request.query_params %} {% comment %}same as {% for param in request.query_params.by_index %} {% endcomment -%}
	{%- unless forloop.first %}, {% endunless %}{{param-}}
{%- endfor -%}
Output
alpha=abc, beta=b, , emptyvariable, animals=cat, animals=dog, animals=fish

The query parameters can be iterated using a {% for %} loop. Note that this includes empty query parameters that do not have keys or values.

Liquid
{%- for param in request.query_params.keys -%}
	{%- unless forloop.first %}; {% endunless %}{{param}}: {{request.query_params[param]-}}
{%- endfor -%}
Output
alpha: abc; beta: b; emptyvariable: ; animals: cat,dog,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.

Properties
Properties of {{ post_params }} objects
Name Type Description
object_type string Will always be post_params
is_valid boolean True if there is at least one posted parameter
by_name object 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
keys list A list containing all of the unique post parameter names
count integer The number of unique post parameter names
length integer The total number of post parameters, including duplicate parameters
* string Specific post parameter values may be accessed using {{ request.post_params.parametername }} or {{ request.post_params['parameter-name'] }}
output string 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.

Example Loop 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.

Properties
Properties of {{ site }} objects
Name Type Description
object_type string Will always be site
is_valid boolean Will always be true
guid string The unique identifier for the site
name string The name of the site
default_domain_name string The domain name of the default domain for the site
default_timezone string The default timezone for the site
default_meta_description string The default meta description for pages on the site
session_length integer The number of minutes that sessions will remain active between requests on the current site
favicon string The URL for this site's favicon (if specified)
liveedit_enabled boolean 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
profiles_enabled boolean True if profiles are currently enabled for this site
signup_enabled boolean True if users are allowed to sign up for their own profiles directly from the live site
profile_id_equals_email boolean True if profiles on this site should use the same value for their id and email. False if the id and email may be different
settings {{ dictionary }} 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 }}
output string A json representation of the site object

The site object is copyable, and when copied will copy all of the site settings to the resulting dictionary.

Example Working 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 -%}

Reference custom fields on the site object

Liquid
{%- if site.custom_property_name -%}
	<p>Custom Property: {{site.custom_property_name}}</p>
{%- endif -%}
{%- if site['custom_property_name_2'] -%}
	<p>Custom Property 2: {{site['custom_property_name_2']}}</p>
{%- endif -%}

{{ automatic_markup }}

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.

Properties
Properties of {{ automatic_markup }} objects
Name Type Description
object_type string Will always be automatic_markup
is_valid boolean Will always be true
title string 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 %}
description string 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 %}
robots string 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 %}
canonical_url string 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 %}
favicon string 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 %}
head_enabled boolean 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 %}
body_enabled boolean 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 %}
show_preview_code boolean 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
show_edit_link boolean 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
header_markup string The markup that will be output to the head of the current page. Equivalent to "{{ header_start_markup }}{{ header_end_markup }}"
header_start_markup string The markup that will be output to the beginning of the head of the current page. This includes the browser title and other meta information
header_end_markup string 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 %}
body_markup string 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 %}
header_scripts list The list of javascript linked_src objects that should be output to the document head as part of the automatic markup
body_scripts list The list of javascript linked_src objects that should be output to the document body as part of the automatic markup
stylesheets list The list of stylesheet linked_src objects that should be output to the document head as part of the automatic markup
body_stylesheets list 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)
output string Deprecated. Contains a long pseudo-random string.