Fix whitespace in periodic summary by inlining albums list
Inline periodic_albums_list computation into periodic_summary_formatted
using {%- -%} whitespace control to prevent unwanted whitespace in the
formatted output. Add documentation about this Jinja2 pattern to CLAUDE.md.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
30
CLAUDE.md
30
CLAUDE.md
@@ -59,4 +59,32 @@ Zigbee/
|
||||
# Author: Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
||||
```
|
||||
|
||||
When any blueprint file is moved ask if I need to update the link somewhere else.
|
||||
When any blueprint file is moved ask if I need to update the link somewhere else.
|
||||
|
||||
## Jinja2 Whitespace Issue
|
||||
|
||||
Home Assistant evaluates all blueprint variables before conditions are checked. When a variable's Jinja2 template contains whitespace (newlines, indentation), that whitespace gets included in the output even if the template logic produces an empty string.
|
||||
|
||||
**Problem:** Using a variable like `{{ my_variable }}` in string replacements will include unwanted whitespace.
|
||||
|
||||
**Solution:** Compute complex values inline where they're used, with `{%- -%}` whitespace control:
|
||||
|
||||
```yaml
|
||||
# BAD - whitespace from my_list variable will be included
|
||||
my_list: >
|
||||
{% for item in items %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
|
||||
result: "{{ template | replace('{items}', my_list) }}"
|
||||
|
||||
# GOOD - inline computation with whitespace control
|
||||
result: >
|
||||
{%- set ns = namespace(items = '') -%}
|
||||
{%- for item in items -%}
|
||||
{%- set ns.items = ns.items ~ item -%}
|
||||
{%- endfor -%}
|
||||
{{ template | replace('{items}', ns.items) }}
|
||||
```
|
||||
|
||||
This pattern is used throughout the Immich Album Watcher blueprint for `common_date`, `common_location`, `video_warning`, and `periodic_albums_list`.
|
||||
|
||||
Reference in New Issue
Block a user