ui.util.keep_item / ui.util.pop_itemsThis pair of function stores and returns arbitrary data during the request. It's similar to flash messages, but can store any kind of data and removes data after request is finished.
{%- call ui.util.call(show_example) -%} {%- raw %} {%- do ui.util.keep_item("random", "a", 1) -%} {%- do ui.util.keep_item("random", "b", 2) -%} {{ ui.util.pop_items("random") | tojson }} {# `c` remains unused and will be dropped after request is finished #} {%- do ui.util.keep_item("random", "c", 3) -%} {%- endraw %} {%- endcall %}
Data is stored as 2-dimensional map. The first level defines category,
the second level contains key of the item. It can be used by ui.util.pop_items which
accepts either a single argument(category) and returns dictionary with
all keys for the category, or two arguments(category and key) and
returns just a single item from the category.
Note, in Jinja2 you do not need to declare kwargs inside macro
signature. Just use variable with name kwargs somewhere inside
macro code and Jinja2 collect all additional arguments into it implicitly.
ui.util.pop_items removes the item/category upon
access. If you want to check the content, but without removing it,
enable keep flag.