jimtng
(jimtng)
August 16, 2026, 9:47am
5
main ← jimtng:yamlcomposer-loops
opened 09:21AM - 16 Aug 26 UTC
## Summary
This PR introduces several significant enhancements to the YAML Comp… oser, focusing on dynamic content generation, improved conditional logic, and expanded expression support.
## Key Features
- **Loop Support (`!for`):** Add a new directive that allows for dynamic sequence iteration and templating within YAML definitions.
- **Key-Level `!if`:** Introduce a shorthand form for the `!if` tag to streamline conditional blocks and improve readability.
- **Range Expressions:** Add support for Jinjava `range()` functions and Ruby-style range syntax (`[1..5]` for inclusive and `[1...5]` for exclusive ranges).
- **Enumerate Support:** Add `enumerate` as both a filter and a function, supporting list and map iteration with `.key` and `.value` accessors.
## Internal Changes
- **Directive Processing Phase:** Introduce a dedicated directive processing phase to the composer's transformation pipeline. This provides a more robust framework for handling structural tags like `!for` and `!if`.
- **Test Suite Reorganization:** The existing test suite has been split into multiple specialized files. This reorganization improves maintainability and makes it easier to navigate the growing number of test cases.
The detailed doc for loops:
# Loops (`!for`)
The `!for` tag performs configuration unrolling and iteration during the **preprocessing phase**.
> **Note:** Iterations are evaluated **once** when the YAML file is loaded.
> These are not runtime rules.
> They do not react to live state changes in openHAB.
[[toc]]
## When to Use `!for`
Use the `!for` tag to dynamically generate repetitive openHAB configuration structures based on the **Resolution Context** (variables defined in the file, injected via `!include` or `!insert`, or [environment globals](variables.md#env-to-access-environment-variables)).
Typical use cases in openHAB:
- **Generate multiple Things** from a list of device IDs.
- **Generate multiple Channels** from structured metadata.
- **Generate multiple Items** from a list, map, or equipment definition.
- **Generate semantic model structures** (rooms, equipment, points).
This file has been truncated. show original
Notably: I haven’t added a break or continue because I don’t think they’re necessary for the case of building a YAML output. If you can think of a reason why they are important to have, please let me know. Currently if you must, you could use several alternatives: using for filtering, or using if inside the loop.