iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
434 stars 56 forks source link

Cannot template list-card #61

Closed viktak closed 3 years ago

viktak commented 3 years ago

Checklist:

Release with the issue: 1.3.0 Last working release (if known):

Browser and Operating System: Windows 10 Pro 64

Description of problem: Trying to template the `list-card' using the following code:

  - type: 'custom:config-template-card'
    entities:
      - sensor.earthquakes
    card:
      type: 'custom:list-card'
      title: Earthquakes
      entity: sensor.earthquakes
      feed_attribute: earthquakes
      columns:
        - title: "Time"
          field: '${ time.strftime("%b %d %X") }'
        - title: "Mag."
          field: magnitude
          style:
            - padding-right: 5px
            - padding-left: 5px
        - title: "Dist."
          field: distance
          postfix: km
          style:
            - padding-right: 5px
            - padding-left: 5px
        - title: "Title"
          field: title
          add_link: link

Line field: '${ time.strftime("%b %d %X") }' causes the whole thing to not render.

{{ state_attr('sensor.earthquakes','earthquakes')[0].time.strftime("%b %d %X") }} in the Template tester renders correctly as Feb 12 12:03:13

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

Additional information: I am using the earthquake integration as a source to the list.

viktak commented 3 years ago

The following code is working properly in a markdown card, so I assume my templates are correct:

  - type: markdown
    title: Recent Earthquakes
    content: |
      {% for quake in state_attr('sensor.earthquakes','earthquakes') %}
      {{ quake.magnitude }}: [{{ quake.title }}]({{ quake.link }}) {{ quake.distance }}km
      {{ quake.time.strftime("%b %d %X")}}
      {% endfor %}
iantrich commented 3 years ago

field is the name of a column, so current time will not work there