format expression docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent d2bf582 · Browse files · 1 file·+37 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+37 added−37 removed
- other:+37 added−37 removed
Provenance
- Commit
a554288- Tree
37c714a- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
d2bf582
1 file changed+37 added−37 removed
modified:docs/templates.rst+37 added-37 removed
1172 unmodified lines1173 1174 The simplest form of expressions are literals. Literals are representations1175 for Python objects such as strings and numbers. The following literals exist:1176 1177-"Hello World":1177+``"Hello World"``1178 Everything between two double or single quotes is a string. They are1179 useful whenever you need a string in the template (e.g. as1180 arguments to function calls and filters, or just to extend or include a1181 template).1182 1183-42 / 123_456:1183+``42`` / ``123_456``1184 Integers are whole numbers without a decimal part. The '_' character1185 can be used to separate groups for legibility.1186 1187-42.23 / 42.1e2 / 123_456.789:1187+``42.23`` / ``42.1e2`` / ``123_456.789``1188 Floating point numbers can be written using a '.' as a decimal mark.1189 They can also be written in scientific notation with an upper or1190 lower case 'e' to indicate the exponent part. The '_' character can1191 be used to separate groups for legibility, but cannot be used in the1192 exponent part.1193 1194-['list', 'of', 'objects']:1194+``['list', 'of', 'objects']``1195 Everything between two brackets is a list. Lists are useful for storing1196 sequential data to be iterated over. For example, you can easily1197 create a list of links using lists and tuples for (and with) a for loop::1198 3 unmodified lines1202 <li><a href="{{ href }}">{{ caption }}</a></li>1203 {% endfor %}1204 </ul>1205 1206-('tuple', 'of', 'values'):1206+``('tuple', 'of', 'values')``1207 Tuples are like lists that cannot be modified ("immutable"). If a tuple1208 only has one item, it must be followed by a comma (``('1-tuple',)``).1209 Tuples are usually used to represent items of two or more elements.1210 See the list example above for more details.1211 1212-{'dict': 'of', 'key': 'and', 'value': 'pairs'}:1212+``{'dict': 'of', 'key': 'and', 'value': 'pairs'}``1213 A dict in Python is a structure that combines keys and values. Keys must1214 be unique and always have exactly one value. Dicts are rarely used in1215 templates; they are useful in some rare cases such as the :func:`xmlattr`1216 filter.1217 1218-true / false:1219- true is always true and false is always false.1218+``true`` / ``false``1219+ ``true`` is always true and ``false`` is always false.1220 1221 .. admonition:: Note1222 1223 The special constants `true`, `false`, and `none` are indeed lowercase.9 unmodified lines1233 1234 Jinja allows you to calculate with values. This is rarely useful in templates1235 but exists for completeness' sake. The following operators are supported:1236 1237-\+1237+``+``1238 Adds two objects together. Usually the objects are numbers, but if both are1239 strings or lists, you can concatenate them this way. This, however, is not1240 the preferred way to concatenate strings! For string concatenation, have1241 a look-see at the ``~`` operator. ``{{ 1 + 1 }}`` is ``2``.1242 1243-\-1243+``-``1244 Subtract the second number from the first one. ``{{ 3 - 2 }}`` is ``1``.1245 1246-/1246+``/``1247 Divide two numbers. The return value will be a floating point number.1248 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.1249 1250-//1250+``//``1251 Divide two numbers and return the truncated integer result.1252 ``{{ 20 // 7 }}`` is ``2``.1253 1254-%1254+``%``1255 Calculate the remainder of an integer division. ``{{ 11 % 7 }}`` is ``4``.1256 1257-\*1257+``*``1258 Multiply the left operand with the right one. ``{{ 2 * 2 }}`` would1259 return ``4``. This can also be used to repeat a string multiple times.1260 ``{{ '=' * 80 }}`` would print a bar of 80 equal signs.1261 1262-\**1262+``**``1263 Raise the left operand to the power of the right operand. ``{{ 2**3 }}``1264 would return ``8``.1265 1266 Comparisons1267 ~~~~~~~~~~~1268 1269-==1269+``==``1270 Compares two objects for equality.1271 1272-!=1272+``!=``1273 Compares two objects for inequality.1274 1275->1276- `true` if the left hand side is greater than the right hand side.1275+``>``1276+ ``true`` if the left hand side is greater than the right hand side.1277 1278->=1279- `true` if the left hand side is greater or equal to the right hand side.1278+``>=``1279+ ``true`` if the left hand side is greater or equal to the right hand side.1280 1281-<1282- `true` if the left hand side is lower than the right hand side.1281+``<``1282+ ``true`` if the left hand side is lower than the right hand side.1283 1284-<=1285- `true` if the left hand side is lower or equal to the right hand side.1284+``<=``1285+ ``true`` if the left hand side is lower or equal to the right hand side.1286 1287 Logic1288 ~~~~~1289 1290-For `if` statements, `for` filtering, and `if` expressions, it can be useful to1290+For ``if`` statements, ``for`` filtering, and ``if`` expressions, it can be useful to1291 combine multiple expressions:1292 1293-and1293+``and``1294 Return true if the left and the right operand are true.1295 1296-or1296+``or``1297 Return true if the left or the right operand are true.1298 1299-not1299+``not``1300 negate a statement (see below).1301 1302-(expr)1303- group an expression.1302+``(expr)``1303+ Parentheses group an expression.1304 1305 .. admonition:: Note1306 1307 The ``is`` and ``in`` operators support negation using an infix notation,7 unmodified lines1315 1316 The following operators are very useful but don't fit into any of the other1317 two categories:1318 1319-in1319+``in``1320 Perform a sequence / mapping containment test. Returns true if the left1321 operand is contained in the right. ``{{ 1 in [1, 2, 3] }}`` would, for1322 example, return true.1323 1324-is1324+``is``1325 Performs a :ref:`test <tests>`.1326 1327-\|1327+``|``1328 Applies a :ref:`filter <filters>`.1329 1330-~1330+``~``1331 Converts all operands into strings and concatenates them.1332 1333 ``{{ "Hello " ~ name ~ "!" }}`` would return (assuming `name` is set1334 to ``'John'``) ``Hello John!``.1335 1336-()1336+``()``1337 Call a callable: ``{{ post.render() }}``. Inside of the parentheses you1338 can use positional arguments and keyword arguments like in Python:1339 1340 ``{{ post.render(user, full=true) }}``.1341 1342-. / []1342+``.`` / ``[]``1343 Get an attribute of an object. (See :ref:`variables`)1344 1345 1346 .. _if-expression:433 unmodified lines