How to create tokens for data binding using Django Bindings

Django Bindings has been deprecated. For more, see the Deprecation Notice.

If you want to use tokens to bind values from different views, you can create tokens within template tags by using the "$" escape character around token variables and appending the token_safe filter as follows:

value="$variablename$"|token_safe

This filter indicates that the value contains a token rather than literal dollar signs.

The following example shows a text box and a search query that share an indexName variable. When an index name is entered into the text box, the "index" property of the search query is updated with the new value, and the search is run again with the updated query:

...
{% block content %}
    {% textinput
        id="txtIndex"
        default="main"
        value="$indexName$"|token_safe %}
{% endblock content %}

{% block managers %}
    {% searchmanager
        id="mySearch"
        search="index=$indexName$"|token_safe %}
{% endblock managers %}
...

A couple of things to note:

  • The token_safe filter is appended to the end of the search query string as well as to the text box value to indicate the values are tokens, not literal values.
  • This text box has a default value. As a result, this value is also the initial value of the $indexName$ token, and therefore the initial value of the index in the search query.

For more about how tokens work, see Tokens in Django Bindings.