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

Reusing macros from templates in lovelace_gen. #52

Open
benjycov opened this issue Jul 18, 2023 · 1 comment
Open

Reusing macros from templates in lovelace_gen. #52

benjycov opened this issue Jul 18, 2023 · 1 comment

Comments

@benjycov
Copy link

I've taken my code reuse to a whole new level and now find myself in the scenario where I have macros that I want to both call from within templates and lovelace_gen. The problem of course is the path, because HA templates look directly in /config/custom_templates, and lovelace_gen needs it to be explicit.

{% macro example() %}
{%- set source_path = '/config/custom_templates/' -%}
{% from source_path + 'data.jinja' import my_data %}
---  do some stuff ---
{% endmacro %}

Can anyone think of any way of detecting from within the macro if its running under lovelace_gen or HA?

I've tried by using the lovelace_gen _global variables, in HA you can use the states function to test the lack of existence of a _global.something, but of course states() isn't available to lovelace_gen, also is defined/undefined doesn't work in HA as it throws an error before it checks it.

The only work arounds I have are to pass a variable in telling the macro where its being called from, or by maintaining two code sets (or wrapping the code somehow) with the source_path set differently, neither are perfect solutions.

Any ideas?

@wbyoung
Copy link

wbyoung commented Feb 18, 2024

I've just started exploring this integration. In addition to the above, I've noticed that break is not supported in Jinja templates, so it seems like the extensions HA enables are not enabled either.

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