Request

Request

{{ 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.

Name Type Description
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

Examples

Getting request parameters and fetching blog_posts

Copy
{% 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 %}

Request Origin

Copy
Origin: {{ request.headers.origin }}

Loop Post Parameters

Copy
<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>