diff options
author | Shams Imam <shams.imam@gmail.com> | 2019-05-31 14:11:28 -0500 |
---|---|---|
committer | Shams Imam <shams.imam@gmail.com> | 2019-05-31 14:18:45 -0500 |
commit | e632dc5f1bba03f51d201ad034870fca2f3ceeaa (patch) | |
tree | be921aa77556fb67e749a33fad3db5265b5c5adf /docs | |
parent | 67e2542dd496f81852e67681a2f9f744fab17bca (diff) | |
download | jinja-e632dc5f1bba03f51d201ad034870fca2f3ceeaa.tar.gz |
adds documentation on use of python methods in expressions
Diffstat (limited to 'docs')
-rw-r--r-- | docs/templates.rst | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/docs/templates.rst b/docs/templates.rst index d10d5e67..2c9fe7e6 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -1309,13 +1309,35 @@ The general syntax is ``<do something> if <something is true> else <do something else>``. The `else` part is optional. If not provided, the else block implicitly -evaluates into an undefined object:: +evaluates into an undefined object: .. sourcecode:: jinja {{ '[%s]' % page.title if page.title }} +.. _python-methods: + +Python Methods +~~~~~~~~~~~~~~ + +You can also use any of the methods of defined on a variable's type. +The value returned from the method invocation is used as the value of the expression. +Here is an example that uses methods defined on strings (where ``page.title`` is a string): + +.. code-block:: text + + {{ page.title.capitalize() }} + +This also works for methods on user-defined types. +For example, if variable ``f`` of type ``Foo`` has a method ``bar`` defined on it, +you can do the following: + +.. code-block:: text + + {{ f.bar() }} + + .. _builtin-filters: List of Builtin Filters |