]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
adds documentation on use of python methods in expressions 1009/head
authorShams Imam <shams.imam@gmail.com>
Fri, 31 May 2019 19:11:28 +0000 (14:11 -0500)
committerShams Imam <shams.imam@gmail.com>
Fri, 31 May 2019 19:18:45 +0000 (14:18 -0500)
docs/templates.rst

index d10d5e6729bb84811a1409ff4b6819e1c914836a..2c9fe7e69317650311b0ca7894012cddf37aac38 100644 (file)
@@ -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