Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

void -> do

--HG--
branch : trunk
  • Loading branch information...
commit 5d2733fce81b22fb53e63c7ea00154c63dae541f 1 parent a78d276
@mitsuhiko authored
View
12 docs/extensions.rst
@@ -25,6 +25,8 @@ example creates a Jinja2 environment with the i18n extension loaded::
i18n Extension
--------------
+**Import name:** `jinja2.ext.i18n`
+
Jinja2 currently comes with one extension, the i18n extension. It 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
@@ -90,6 +92,16 @@ The usage of the `i18n` extension for template designers is covered as part
.. _Babel: http://babel.edgewall.org/
+do
+~~
+
+**Import name:** `jinja2.ext.do`
+
+The do aka expression-statement extension adds a simple `do` tag to the
+template engine that works like a variable expression but ignores the
+return value.
+
+
.. _writing-extensions:
Writing Extensions
View
10 docs/templates.rst
@@ -1012,3 +1012,13 @@ To use placeholders you can use the `format` filter::
For multiple placeholders always use keyword arguments to `format` as other
languages may not use the words in the same order.
+
+
+do
+~~
+
+If the expression-statement extension is loaded a tag called `do` is available
+that works exactly like the regular variable expression (``{{ ... }}``) just
+that it doesn't print anything. This can be used to modify lists:
+
+ {% do navigation.append('a string') %}
View
2  jinja2-debug.py
@@ -13,7 +13,7 @@
import jinja2
from werkzeug import script
-env = jinja2.Environment(extensions=['jinja2.ext.i18n'])
+env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do'])
def shell_init_func():
def _compile(x):
View
3  jinja2/defaults.py
@@ -25,8 +25,7 @@
DEFAULT_NAMESPACE = {
'range': xrange,
'dict': lambda **kw: kw,
- 'lipsum': generate_lorem_ipsum,
- 'void': lambda *a: u''
+ 'lipsum': generate_lorem_ipsum
}
View
13 jinja2/ext.py
@@ -277,6 +277,18 @@ def _make_node(self, singular, plural, variables, plural_expr):
return nodes.Output([node])
+class ExprStmtExtension(Extension):
+ """Adds a `do` tag to Jinja2 that works like the print statement just
+ that it doesn't print the return value.
+ """
+ tags = set(['do'])
+
+ def parse(self, parser):
+ node = nodes.ExprStmt(lineno=parser.stream.next().lineno)
+ node.node = parser.parse_tuple()
+ return node
+
+
def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS):
"""Extract localizable strings from the given template node.
@@ -360,3 +372,4 @@ def babel_extract(fileobj, keywords, comment_tags, options):
#: nicer import names
i18n = InternationalizationExtension
+do = ExprStmtExtension
Please sign in to comment.
Something went wrong with that request. Please try again.