[FR]: Pass object variables in JSON format when used in templates
Hi code owners
Updated to a FR, 8 June 2024: Decluttering card is really a great project. I recently discovered it and I love it 😊
I noticed that we can pass both object and strings as variables. Directly assign object variables (e.g list) to a key in the card works. I'm stuck passing object variables and use them in templates.
I either get a string that contains [[undefined]], [[variable name]] or the default value 'xxx' declared as a string.
I tried this markdown card template:
decl_test_var:
default:
- VALUE: xxx
card:
type: markdown
content: "{{ '[[VALUE]]' }}"
With this card:
type: custom:decluttering-card
template: decl_test_var
variables:
- VALUE:
- tst1.x
- tst2.y
That doesn't work. There seems no way to pass the object variables into a template
FR: Please pass object variables as a json string when applied inside a template. A special marker like this would be fine:
content: "{{ '[[VALUE:JSON]]' }}"
Thanks in advance Eric
It's because it injects the YAML itself. So VALUE is returning:
- VALUE:
- tst1.x
- tst2.y
Instead you can try:
- VALUE: '[tst1.x, tst2.y]'
And remove the quotes around [[VALUE]]
This is really only an issue with Jinja. I use lists elsewhere in my configuration but usually to add cards to a stack.
@droans ah thanks, now I understand what happens. I already found out to pass them as a string, but this was just a simplified example without sub-keys. I will change this question into a FR to pass objects in JSON format when the variables are used inside templates. Thanks!