iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
425 stars 55 forks source link

can not use multi-line? with an unusual fix... #94

Closed Mariusthvdb closed 2 years ago

Mariusthvdb commented 2 years ago

Checklist:

Release with the issue: 1.3.6 Last working release (if known): dk Browser and Operating System: Any browser (Safari, Firefox, Chrome) on MacOS 12.0.1

Description of problem:

using:

      - type: custom:config-template-card
        entities:
          - input_number.power_threshold
        variables:
          threshold: states['input_number.power_threshold'].state
        row:
          type: section
          label: >
            ${'Above: ' + threshold}
Schermafbeelding 2022-01-06 om 15 44 14

I always try to use multi-line notation to prevent quoting issues, and therefor tested:

        row:
          type: section
          label: >
            ${'Above: ' + threshold}

however this is not accepted, and errors with

Javascript errors shown in the web inspector (if applicable):

Uncaught (in promise) SyntaxError: Unexpected token '}'
    at HTMLElement._evaluateTemplate (config-template-card.js?v=1.3.6:912)
    at config-template-card.js?v=1.3.6:860
    at Array.forEach (<anonymous>)
    at HTMLElement._evaluateConfig (config-template-card.js?v=1.3.6:849)
    at HTMLElement.render (config-template-card.js?v=1.3.6:807)
    at HTMLElement.update (config-template-card.js?v=1.3.6:265)
    at HTMLElement.performUpdate (config-template-card.js?v=1.3.6:252)
    at HTMLElement.scheduleUpdate (config-template-card.js?v=1.3.6:252)
    at HTMLElement._$EC (config-template-card.js?v=1.3.6:252)

Additional information: since instruction show to always use {}, I can not understand the error about the unexpected token '}'... still, following that error output I unbelievingly tried:

        row:
          type: section
          label: >
            ${'Above:  ' + threshold

and lo and behold, that seems to work alright. Must be a fluke of some kind. and user error?

iantrich commented 2 years ago
              label: >-
                ${"Favorites - " +
                states['climate.thermostat'].attributes.current_temperature +
                "°/" + states['climate.thermostat'].attributes.temperature +
                "°"}
Mariusthvdb commented 2 years ago

thanks! can confirm:

    row:
      type: section
      label: >-
        ${'Above: ' + threshold}

works, and notice that we need the >- instead of single >

would you be able to explain why the odd solution in my post above did work? without the ending }

anyways, thanks again.