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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Utilities | Jinja Documentation</title>
<style text="text/css">
body {
font-family: 'Arial', sans-serif;
margin: 1em;
padding: 0;
}
#navigation {
float: right;
margin: -1em -1em 1em 1em;
padding: 1em 2em 0 2em;
border: 1px solid #bbb;
border-width: 0 0 1px 1px;
background-color: #f8f8f8;
}
#page {
width: 45em;
}
a {
color: #d00;
}
a:hover {
color: #d40;
}
h1 {
font-size: 2em;
color: #d00;
margin: 0.5em 0 0.5em 0;
padding: 0;
}
h2 {
font-size: 1.7em;
color: #bd2121;
margin: 1em 0 0.5em 0;
}
h3 {
font-size: 1.3em;
color: #8a2424;
margin: 0.5em 0 0 0;
}
p {
margin: 0.5em 1em 0.5em 1em;
}
pre {
margin: 1em 0 1em 2em;
padding: 0.5em;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
background-color: #f2f2f2;
overflow: auto;
}
li {
line-height: 1.4em;
}
hr {
margin: 1em;
padding: 0;
height: 1px!important;
background-color: #ccc;
border: none!important;
}
div.admonition {
margin: 1em 0 1em 1.5em;
padding: 0.5em 0.5em 0.5em 2em;
background-color: #f6e3e3;
border: 1px solid #d50000;
border-left: none;
border-right: none;
}
div.admonition p.admonition-title {
font-size: 1.1em;
color: #d40;
font-weight: bold;
margin: 0 0 0.5em -1em;
}
table {
border-collapse: collapse;
margin: 1em 2em 1em 1.5em;
}
table td, table th {
text-align: left;
border: 1px solid #eee;
padding: 0.3em;
}
table th {
background-color: #d00000;
color: white;
border: 1px solid #d00000;
border-bottom: 1px solid #eee;
}
</style>
</head>
<body>
<div id="navigation">
<h3>Documentation</h3>
<ul>
<li><a href="index.html">back to index</a></li>
<li><a href="http://wsgiarea.pocoo.org/repos/jinja/trunk/docs/source/utils.txt">view source online</a></li>
</ul>
<h3>Table of Contents</h3>
<ul>
<li><a href="#capture-output">Capture Output</a></li>
<li><a href="#modify-set-variables">Modify / Set Variables</a></li>
</ul>
</div>
<h1>Utilities</h1>
<div id="page">
<p>Jinja comes with some utility tags shipped. Those arn't necessary but can help
you with your templates.</p>
<div class="section">
<h2><a id="capture-output" name="capture-output">Capture Output</a></h2>
<p>Captures output and stores it in a variable:</p>
<pre class="literal-block">
{% capture as loopdata %}
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption|escapexml }}</a></li>
{% endfor %}
{% endcapture %}
</pre>
<p>The output of the for loop is now stored in the variable <tt class="docutils literal"><span class="pre">loopdata</span></tt>.</p>
<p>This allows the double usage of block tags:</p>
<pre class="literal-block">
{% capture as title %}{% marker "title" %}{% endcapture %}
<html>
<head>
<title>{{ title|escapexml }} | My Webpage</title>
</head>
<body>
<h1>{{ title }}</h1>
{% marker "body" %}
</body>
</html>
</pre>
</div>
<div class="section">
<h2><a id="modify-set-variables" name="modify-set-variables">Modify / Set Variables</a></h2>
<p><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">define</span> <span class="pre">%}</span></tt> allows you to set a variable.</p>
<p>Usage:</p>
<pre class="literal-block">
{% define my_variable "Some Value" %}
</pre>
<p>You can also apply filters:</p>
<pre class="literal-block">
{% define escaped content | escapexml %}
</pre>
</div>
</div>
</body>
</html>
|