Skip to content
Myr

adds documentation on use of python methods in expressions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Shams Imam · committed by Shams Imam · parent 67e2542 · Browse files · 1 file+23 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−1 removed

  • other:+23 added−1 removed

1 file+23 added−1 removed

modified:docs/templates.rst+23 added-1 removed
1307 unmodified lines
1308The general syntax is ``<do something> if <something is true> else <do1309something else>``.13101311The `else` part is optional. If not provided, the else block implicitly1312evaluates into an undefined object::1312evaluates into an undefined object:13131314.. sourcecode:: jinja13151316 {{ '[%s]' % page.title if page.title }}131713181319.. _python-methods:13201321Python Methods1322~~~~~~~~~~~~~~13231324You can also use any of the methods of defined on a variable's type.1325The value returned from the method invocation is used as the value of the expression.1326Here is an example that uses methods defined on strings (where ``page.title`` is a string):13271328.. code-block:: text13291330 {{ page.title.capitalize() }}13311332This also works for methods on user-defined types.1333For example, if variable ``f`` of type ``Foo`` has a method ``bar`` defined on it,1334you can do the following:13351336.. code-block:: text13371338 {{ f.bar() }}133913401341.. _builtin-filters:13421343List of Builtin Filters1344-----------------------
347 unmodified lines