-
Notifications
You must be signed in to change notification settings - Fork 23
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
Global macros? #32
Comments
+1 for this. There is really only 3 marcos I would really love to be global. Basically being able to recursively print an object. If you just do
|
Would also like to see this. |
Recently discovered this gem, lovelace_gen, and I am using it avidly. However, I use several include files that contain the same macros. So I would love to see something like global macros or macro include files to minimize the size of the yaml files and the need to change multiple files if I adjust a macro that is used in multiple files. So hereby, I add my +1 for this request |
Hey there, I encountered the same issue, and after doing some research, I found that creating Jinja templates like in Flask's was impossible in this context. Here's how I managed to resolve the issue. It's a bit of a workaround, but it got the job done. Note about the files: The white space might not be perfectly aligned as I copied this from my lovelace, which has cards in both vertical and horizontal stacks.
# lovelace_gen
{% set room_chips = [("sensor.temperature", "mdi:thermometer", "state"),
("sensor.humidity", "mdi:water-percent", "state")] %}
title: Test
path: test
cards:
- !include
- "include/chips.yaml"
- room:
{% for entity, icon, primary_info in desk_room_chips %}
- - {{entity}}
- {{icon}}
- {{primary_info}}
{% endfor %}
ws: 1
# lovelace_gen
{{" "*ws}}type: custom:mushroom-chips-card
{{" "*ws}}chips:
{{" "*ws}} {% for entity, icon, primary_info in room %}
{{" "*ws}} - type: entity
{{" "*ws}} entity: {{ entity }}
{{" "*ws}} icon: {{ icon }}
{{" "*ws}} content_info: {{ primary_info }}
{{" "*ws}} tap_action:
{{" "*ws}} action: none
{{" "*ws}} hold_action:
{{" "*ws}} action: none
{{" "*ws}} double_tap_action:
{{" "*ws}} action: none
{{" "*ws}} {% endfor %} It might look a bit messy, but it served as a temporary solution until I find a cleaner approach. EDIT: After reading the documentation, I found a better way to call my included file with json variables:
# lovelace_gen
{% set room_chips = [("sensor.temperature", "mdi:thermometer", "state"),
("sensor.humidity", "mdi:water-percent", "state")] %}
title: Test
path: test
cards:
- !include
- "include/chips.yaml"
- room: {{ room_chips | tojson }}
ws: 1 |
Hi Thomas,
is there a chance global macros could be supported? I remember a pull request by Rocka84 for the "old" Lovelace_gen.py project that was a great attempt IMHO. Global macros would totally be a game changer for me...
The text was updated successfully, but these errors were encountered: