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

alternate template engines possible? #13

Open
dkebler opened this issue Apr 20, 2020 · 1 comment
Open

alternate template engines possible? #13

dkebler opened this issue Apr 20, 2020 · 1 comment

Comments

@dkebler
Copy link

dkebler commented Apr 20, 2020

First of all...excellent and super useful component for groups of related entities like my bank of irrigation solenoids, thx.

Being a nodejs coder and pretty much a noob at python I'm finding jinja2 painful.

I understand the backend of HA is python but that shouldn't mean that lovelace can't support template engines using another language? Javascript for example...aaahh. If so how hard would that be to include others?

i.e. one of these https://colorlib.com/wp/top-templating-engines-for-javascript/

Jade/Pug is a good one and there is a maintained python package for that.
https://pypi.org/project/pypugjs/

In the meantime can you give me a little jinja2 help?

I have this working

# lovelace_gen
{% set zones = ['1','2','3'] %}
icon: mdi:water
cards:
  - type: vertical-stack
    cards:
    - type: markdown
      content: >
        # Irrigation
    {% for zone in zones %}
    - type: entity-button
      entity: switch.irrigation_zone_{{ zone }}
      icon: mdi:water
      name: zone
      tap_action:
      action: toggle
    {% endfor %}

but I want to use a hash but can't find any jinga2 examples to help out and of have no idea how python does object hash.

# lovelace_gen
?? set a hash?? seems set is for iterable only
{% zones = { '1':'Front North', '2':'Front South', '3':'Front Beds'} %}
icon: mdi:water
cards:
  - type: vertical-stack
    cards:
    - type: markdown
      content: >
        # Irrigation
    {% for zone in Object.keys(zones) %}  // Object.keys is JS :-)
    - type: entity-button
      entity: switch.irrigation_zone_{{ zone }}
      icon: mdi:water
      name: {{ zones[zone] }}
      tap_action:
       action: toggle
    {% endfor %}
@dkebler
Copy link
Author

dkebler commented Apr 21, 2020

I'd still be interested in alternative template engines but I did figure out how to iterate the keys/values of a object hash in jinja

# lovelace_gen
{% set zones = { '1':'Front North', '2':'Front South', '3':'Front Beds'} %}
icon: mdi:water
cards:
  - type: vertical-stack
    cards:
    - type: markdown
      content: >
        # Irrigation
    - type: horizontal-stack
      cards:
        {% for zone,name in zones.items() %}
        - type: entity-button
          entity: switch.irrigation_zone_{{ zone }}
          icon: mdi:water
          name: {{ name }}
          tap_action:
            action: toggle
        {% endfor %}

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

1 participant