From e632dc5f1bba03f51d201ad034870fca2f3ceeaa Mon Sep 17 00:00:00 2001 From: Shams Imam Date: Fri, 31 May 2019 14:11:28 -0500 Subject: [PATCH] adds documentation on use of python methods in expressions --- docs/templates.rst | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 -- 2.47.2