File: utils.txt

package info (click to toggle)
jinja 0.9-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 412 kB
  • ctags: 485
  • sloc: python: 2,551; makefile: 40
file content (48 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
=========
Utilities
=========

Jinja comes with some utility tags shipped. Those arn't necessary but can help
you with your templates.


Capture Output
==============

Captures output and stores it in a variable::

    {% capture as loopdata %}
        {% for item in navigation %}
            <li><a href="{{ item.href }}">{{ item.caption|escapexml }}</a></li>
        {% endfor %}
    {% endcapture %}

The output of the for loop is now stored in the variable ``loopdata``.

This allows the double usage of block tags::

    {% capture as title %}{% marker "title" %}{% endcapture %}
    <html>
        <head>
            <title>{{ title|escapexml }} | My Webpage</title>
        </head>
        <body>
            <h1>{{ title }}</h1>
            {% marker "body" %}
        </body>
    </html>


Modify / Set Variables
======================

``{% define %}`` allows you to set a variable.

Usage::

    {% define my_variable "Some Value" %}

You can also apply filters::

    {% define escaped content | escapexml %}