**Import name:** `jinja2.ext.i18n`
-The i18n extension can be used in combination with `gettext`_ or `babel`_. If
-the i18n extension is enabled Jinja2 provides a `trans` statement that marks
+The i18n extension can be used in combination with `gettext`_ or `babel`_. If
+the i18n extension is enabled Jinja2 provides a `trans` statement that marks
the wrapped string as translatable and calls `gettext`.
After enabling, dummy `_` function that forwards calls to `gettext` is added
The current :class:`~jinja2.lexer.TokenStream`
.. autoclass:: jinja2.lexer.TokenStream
- :members: push, look, eos, skip, next, next_if, skip_if, expect
+ :members: push, look, eos, skip, __next__, next_if, skip_if, expect
.. attribute:: current
gets rendered with blank lines inside the div::
<div>
-
+
yay
-
+
</div>
But with both `trim_blocks` and `lstrip_blocks` enabled, the template block
lines are removed and other whitespace is preserved::
-
+
<div>
yay
</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When automatic escaping is enabled, everything is escaped by default except
-for values explicitly marked as safe. Variables and expressions
+for values explicitly marked as safe. Variables and expressions
can be marked as safe either in:
a. the context dictionary by the application with `MarkupSafe.Markup`, or
b. the template, with the `|safe` filter
-
+
The main problem with this approach is that Python itself doesn't have the
concept of tainted values; so whether a value is safe or unsafe can get lost.
The `else` part is optional. If not provided, the else block implicitly
evaluates into an undefined object::
+.. sourcecode:: jinja
+
{{ '[%s]' % page.title if page.title }}
return self.next_if(expr) is not None
def __next__(self):
- """Go one token ahead and return the old one"""
+ """Go one token ahead and return the old one.
+
+ Use the built-in :func:`next` instead of calling this directly.
+ """
rv = self.current
if self._pushed:
self.current = self._pushed.popleft()