ui.util.augment_attrs
Apply default values to the attrs item of the dictionary.
This function is used internally inside ui.util.attrs. Following
two examples are approximately the same.
This function can be called when macro needs to set default attributes before delegating call to a different macro.
{%- call ui.util.call(show_example) -%} {%- raw %} {%- macro button_with_id(content, id) -%} {%- set updated_kwargs = ui.util.augment_attrs(kwargs, {"id": id}) -%} {{ ui.button(content, **updated_kwargs) }} {%- endmacro %} {{ button_with_id("Click", id="test-id") }} {%- endraw %} {%- endcall %}
By default it updates attrs item in the dictionary, but
you can change this behavior by providing key argument. If
it's non-empty string, corresponding item will be updated. If it's a
falsy value, the top-level will be updated
Only missing items will be applied. If target item already contains value for the one of default keys, it will remain unchanged.
{%- call ui.util.call(show_example) -%} {%- raw %} {%- set data = {"attrs": {"a": 42}} -%} {%- do ui.util.augment_attrs(data, {"a": 1, "b": 2}) -%} {{ data | tojson }} {%- endraw %} {%- endcall %}