request

Table of contents

The request object has attributes of the current state of the web page.

request.format

Returns format of current request.

{{ request.format }}
Input (on regular url, like /posts)
"html"
Output
{{ request.format }}
Input (on specific url, like /posts.xml)
"xml"
Output

request.fullpath

Returns full path, include query string.

{{ request.fullpath }}
Input
/this/is-a/path?full=1
Output

request.language

Returns a language object for the current language.

{{ request.language }}
Input, on a post that has the german language, e.g. /de/deutches-post
{ "shortcode" => "de", "name" => "German, "url" => "/de/deutches-post" }
Output

request.path

Returns only path, without query string.

{{ request.path }}
Input
/this/is-a/path
Output

request.query

Returns query string. Everything after ‘?’.

{{ request.query }}
Input
full=1&page=5
Output

request.query_object

Converts the query string into an object

{{ request.query_object }}
Input
{"full" => "1", "page" => "5"}
Output
{{ request.query_object.page }}
Input
5
Output

request.url

Returns the full current url.

{{ request.url }}
Input
https://www.my-plate-site.com/this/is-a/path?full=1
Output

request.flash

Contains browser flash messages like form errors.

{{ request.flash.alert }}
{% for error_msg in request.flash.errors %}
  - {{ error_msg }}
{% endfor %}
Input
Something went wrong while sending the message.
- Name is required
- Email is invalid
Output

request.user_agent

Returns the user agent.

{{ request.user_agent }}
Input
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" 
Output

request.body

Returns the request body for POST and PUT requests. Returns `nil` on GET requests

{{ request.body }}
Input
{"param" => "yourbodyparam"}
Output

request.request_method

Returns HTTP request method for current request. One of GET, POST or PUT.

{{ request.request_method }}
Input
"GET"
Output

request.inline_cms_active

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.

{% 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 %}
Input
Inline CMS is now active
Output, if user is logged into the inline CMS
This will be visible only to persons not logged into the inline CMS
Output, if user is not logged into the inline CMS

request.csp_nonce

Returns the nonce that can be used for inline scripts to implement the Content Security Policy of your site properly.

<script nonce="{{ request.csp_nonce }}">
    ...
</script>
Input
<script nonce="Rand)mNonCe">
    ...
</script>
Output

Need help?

Do you have any question which is not answered in this knowledge base? Contact us. We are here to help you.