Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR]: Pass object variables in JSON format when used in templates #83

Open
erkr opened this issue May 30, 2024 · 2 comments
Open

[FR]: Pass object variables in JSON format when used in templates #83

erkr opened this issue May 30, 2024 · 2 comments

Comments

@erkr
Copy link

erkr commented May 30, 2024

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

@droans
Copy link

droans commented Jun 7, 2024

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.

@erkr
Copy link
Author

erkr commented Jun 8, 2024

@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!

@erkr erkr changed the title Question: can I use list variables in template?! [FR]: Pass object variables in JSON format when used in templates Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants