Go to page content


Access request variables from a template.

Sometimes you need direct access to request variables in your template.  The m_req model is meant for this.  It exposes some values from the Webmachine request record.

Dumping all request variables

This will give a complete overview of all request variables:

{% print m.req|make_list %}

This will show something like:

           {"accept-encoding","gzip, deflate"},
           {"cookie","z_sid=1RrDIvFVsoyLgtSU62mN; z_pid=HRrAaiPI08Il4Nu4wST1"},
            "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16"}]}]

Fetching a single value

You can fetch individual values by key, for example:

{{ m.req.host|escape }}

Please note that all values are raw and not escaped, take care to escape the values before you use them in your templates.

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.