Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

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

request.format

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

Returns full path, include query string.

Input:

{{ request.fullpath }}

Output:

/this/is-a/path?full=1

request.language

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" }

request.path

Returns only path, without query string.

Input:

{{ request.path }}

Output:

/this/is-a/path

request.query

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.

request.query_object

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.

request.url

Returns the full current url.

Input:

{{ request.url }}

Output:

https://www.my-plate-site.com/this/is-a/path?full=1

request.flash

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

request.user_agent

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" 

request.body

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

Input:

{{ request.body }}

Output:

{"param" => "yourbodyparam"}

request.request_method

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

Input

{{ request.request_method }}

Output:

"GET"

 

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.

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
  • No labels