Skip to content
Myr

Merge pull request #1009 from shamsimam/doc-python-methods

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

adds documentation on use of python methods in expressions

authored by Joshua Bronson · committed by GitHub · parents 22e0bfc, e632dc5 · 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
1308 unmodified lines
1309The general syntax is ``<do something> if <something is true> else <do1310something else>``.13111312The `else` part is optional. If not provided, the else block implicitly1313evaluates into an undefined object::1313evaluates into an undefined object:13141315.. sourcecode:: jinja13161317 {{ '[%s]' % page.title if page.title }}131813191320.. _python-methods:13211322Python Methods1323~~~~~~~~~~~~~~13241325You can also use any of the methods of defined on a variable's type.1326The value returned from the method invocation is used as the value of the expression.1327Here is an example that uses methods defined on strings (where ``page.title`` is a string):13281329.. code-block:: text13301331 {{ page.title.capitalize() }}13321333This also works for methods on user-defined types.1334For example, if variable ``f`` of type ``Foo`` has a method ``bar`` defined on it,1335you can do the following:13361337.. code-block:: text13381339 {{ f.bar() }}134013411342.. _builtin-filters:13431344List of Builtin Filters1345-----------------------
347 unmodified lines