The request object has attributes of the current state of the web page.
Returns format of current request.
Input (on regular url, like /posts)
{{ request.format }} |
Output:
"html" |
Input (on specific url, like /posts.xml)
{{ request.format }} |
Output:
"xml" |
Request.format only allows: xml, html and json. |
Returns full path, include query string.
Input:
{{ request.fullpath }} |
Output:
/this/is-a/path?full=1 |
Returns a language object for the current language.
Input:
{{ request.language }} |
On a post that has the german language, e.g. /de/deutches-post
Output:
{ "shortcode" => "de", "name" => "German, "url" => "/de/deutches-post" } |
Returns only path, without query string.
Input:
{{ request.path }} |
Output:
/this/is-a/path |
Returns query string. Everything after ‘?’.
Input:
{{ request.query }} |
Output:
full=1&page=5 |
Be aware of the risk of cross site scripting (XSS) vulnerability. Do not directly render the query string in your templates. |
Converts the query string into an object
Input:
{{ request.query_object }} |
Output:
{"full" => "1", "page" => "5"} |
Input:
{{ request.query_object.page }} |
Output:
5 |
Be aware of the risk of cross site scripting (XSS) vulnerability. Do not directly render any query object variable in your templates. |
Returns the full current url.
Input:
{{ request.url }} |
Output:
https://www.my-plate-site.com/this/is-a/path?full=1 |
Contains browser flash messages like form errors.
Input:
{{ request.flash.alert }} {% for error_msg in request.flash.errors %} - {{ error_msg }} {% endfor %} |
Output:
Something went wrong while sending the message. - Name is required - Email is invalid |
Returns the user agent.
Input
{{ request.user_agent }} |
Output:
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" |
Returns the request body for POST and PUT requests. Returns `nil` on GET requests
Input:
{{ request.body }} |
Output:
{"param" => "yourbodyparam"} |
Returns HTTP request method for current request. One of GET, POST or PUT.
Input
{{ request.request_method }} |
Output:
"GET" |
Returns true when the request comes from a user using the inline CMS. So this returns false when a regular site visitor visits a page. This allows for showing/hiding specific data to CMS users or site visitors.
Input:
{% if request.inline_cms_active %} Inline CMS is now active {% else %} This will be visible only to persons not logged into the inline CMS {% endif %} |
Output:
If user is logged into the inline CMS:
Inline CMS is now active |
If user is not logged into the inline CMS:
This will be visible only to persons not logged into the inline CMS |