Post Params

Post Params

{{ post_params }}

Object containing all of the HTTP posted parameters from the current request.

Properties of {{ post_params }} objects
Name Type Description
is_valid Boolean True if there is at least one posted parameter
by_name object An object whose properties match the posted parameters from the request. If the same parameter has multiple values, they will be included as a list of strings rather than simply as a single string, and when treated as a single string the values will be comma-delimited
keys list A list containing all of the unique post parameter names
count Integer The number of unique post parameter names
length Integer The total number of post parameters, including duplicate parameters
* String Specific post parameter values may be accessed using {{ request.post_params.parametername }} or {{ request.post_params['parameter-name'] }}
output String The posted parameters formatted similar to a query parameter string (ie: as if the post request used a content-type of application/x-www-form-urlencoded)

You may treat the post_params object as a list containing all of the parameters which may be iterated using a {% for %} loop. The post_params object is copyable using the {% copy_to_dictionary %} method.

Related

object

May be any object, including simple, complex and list objects. In some cases may even include symbols and null.

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

{{ blog_post }}

string

Can be any text, from the empty string ("") to the full HTML output of the template. When used alone in a conditional, all strings evaluates as true - even if they are empty or a value such as "0" or "false".

{{ query_params }}

Object containing all of the query string parameters for the current page.

number

Can be any number, including integers, decimals, or the value 0. Any value - including 0 - evaluates as true when used alone in a conditional.

{% blog_post %}

integer

A whole (non-fractional, non-decimal) number. May be 0. Any value - including 0 - evaluates as true when used alone in a conditional.

list

An enumerable list containing zero or more objects. Lists may contain many different object types, although most lists only contain a single object type. There are a large number of other complex object types that are also lists (ag: an articlelist is a complex object but is also a list of article objects).

Examples

Demonstrates how to loop Post Parameters.

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>

Demonstrates how to copy Dictionary.

Copy Dictionary

Copy
{% create_dictionary pagination = limit:5 page:2 %}
{% create_dictionary sorting = sort_by:"post_date" sort_direction: "desc" %}

{% comment %}This will create a new dictionary if it does not already exist. Any previous filters may be overwritten from request.post_params.{% endcomment %}
{% copy_to_dictionary filters = request.post_params pagination sorting %}

{% comment %}If you use the new_only instruction then previous filters will not be overwritten.{% endcomment %}
{% create_dictionary filters = blog:entity.blog_main tag:entity.tag_filter %}
{% copy_to_dictionary filters = pagination sorting request.post_params new_only %}

Demonstrates how to getting post parameters.

Getting post parameters

Copy
{% if request.post_params.is_valid %}
{% assign var username = request.post_params['username'] %}
{% assign var password = request.post_params['password'] %}
{% if username is_valid and password is_valid %}
{% auth login username password %}
{% endif %}
{% endif %}
{% unless auth.logged_in %}
<p>Could not log in</p>
{% endunless %}