blob: be832b5319c64355aaaa6e7ba30f282334e9bf65 [file] [edit]
---
title: 'TemplateDict'
---
An Args-like structure for use in ctx.actions.expand_template(), which allows for deferring evaluation of values till the execution phase.
## Members
* [add](#add)
* [add_joined](#add_joined)
## add
```
TemplateDict TemplateDict.add(key, value)
```
Add a String value
### Parameters
| Parameter | Description |
| --- | --- |
| `key` | [string](/versions/9.1.0/rules/lib/core/string); required A String key |
| `value` | [string](/versions/9.1.0/rules/lib/core/string); required A String value |
## add_joined
```
TemplateDict TemplateDict.add_joined(key, values, *, join_with, map_each, uniquify=False, format_joined=None, allow_closure=False)
```
Add depset of values
### Parameters
| Parameter | Description |
| --- | --- |
| `key` | [string](/versions/9.1.0/rules/lib/core/string); required A String key |
| `values` | [depset](/versions/9.1.0/rules/lib/builtins/depset); required The depset whose items will be joined. |
| `join_with` | [string](/versions/9.1.0/rules/lib/core/string); required A delimiter string used to join together the strings obtained from applying `map_each`, in the same manner as [`string.join()`](/versions/9.1.0/rules/lib/core/string#join). |
| `map_each` | callable; required A Starlark function accepting a single argument and returning either a string, `None`, or a list of strings. This function is applied to each item of the depset specified in the `values` parameter |
| `uniquify` | [bool](/versions/9.1.0/rules/lib/core/bool); default is `False` If true, duplicate strings derived from `values` will be omitted. Only the first occurrence of each string will remain. Usually this feature is not needed because depsets already omit duplicates, but it can be useful if `map_each` emits the same string for multiple items. |
| `format_joined` | [string](/versions/9.1.0/rules/lib/core/string); or `None`; default is `None` An optional format string pattern applied to the joined string. The format string must have exactly one '%s' placeholder. |
| `allow_closure` | [bool](/versions/9.1.0/rules/lib/core/bool); default is `False` If true, allows the use of closures in function parameters like `map_each`. Usually this isn't necessary and it risks retaining large analysis-phase data structures into the execution phase. |