diff --git a/docs/docs/report/helpers.md b/docs/docs/report/helpers.md index 443fab8585..8a0c1fa948 100644 --- a/docs/docs/report/helpers.md +++ b/docs/docs/report/helpers.md @@ -14,6 +14,25 @@ Some common functions are provided for use in custom report and label templates. !!! tip "Use the Source, Luke" To see the full range of available helper functions, refer to the source file [report.py](https://github.com/inventree/InvenTree/blob/master/InvenTree/report/templatetags/report.py) where these functions are defined! +## Assigning Variables + +When making use of helper functions within a template, it can be useful to store the result of the function to a variable, rather than immediately rendering the output. + +For example, using the [render_currency](#rendering-currency) helper function, we can store the output to a variable which can be used at a later point in the template: + +```html +{% raw %} + +{% load report %} + +{% render_currency 12.3 currency='USD' as myvar %} +... +... +Result: {{ myvar }} + +{% endraw %} +``` + ## Data Structure Access A number of helper functions are available for accessing data contained in a particular structure format: @@ -24,7 +43,8 @@ To return the element at a given index in a container which supports indexed acc ```html {% raw %} -Item: {% getindex my_list 1 %} +{% getindex my_list 1 as value %} +Item: {{ value }} {% endraw %} ``` @@ -32,11 +52,13 @@ Item: {% getindex my_list 1 %} To return an element corresponding to a certain key in a container which supports key access (such as a [dictionary](https://www.w3schools.com/python/python_dictionaries.asp)), use the `getkey` function: + ```html {% raw %}