From: Shams Imam Date: Fri, 31 May 2019 19:11:28 +0000 (-0500) Subject: adds documentation on use of python methods in expressions X-Git-Tag: 2.10.2~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1009%2Fhead;p=thirdparty%2Fjinja.git adds documentation on use of python methods in expressions --- 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 `` if 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