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

[Suggestion] Change Jinja Escape Character #18

Open
Matchlighter opened this issue Sep 6, 2020 · 3 comments
Open

[Suggestion] Change Jinja Escape Character #18

Matchlighter opened this issue Sep 6, 2020 · 3 comments

Comments

@Matchlighter
Copy link
Contributor

I've been dealing with a number of usability issues when trying to use Home Assistant xyz_template keys in Lovelace. I feel like {% raw %} and {{ '{{' }} are very ugly and verbose with as much as I'm trying to use them. I was looking at the Jinja docs and noted the following options on the Jinja Environment object:

block_start_string
The string marking the beginning of a block. Defaults to '{%'.
block_end_string
The string marking the end of a block. Defaults to '%}'.
variable_start_string
The string marking the beginning of a print statement. Defaults to '{{'.
variable_end_string
The string marking the end of a print statement. Defaults to '}}'.

What are your thoughts on changing those to something else, eg square brackets such as [[ .. ]] and [% ... %] or angle brackets such as <{ ... }> and <% ... %>? (Other ideas?)

Given that such a change would be a breaking one, I was thinking that it could be added as an option in the lovelace_gen: configuration.yaml entry. For easier entry for new users going forward, I feel like this change should be the default, but that would require action on the part of existing users...

I'm more than happy to throw in a PR for this, but wanted to get your thoughts beforehand.

@thomasloven
Copy link
Owner

Lovelace_gen doesn't provide the jinja engine by itself, but instead piggy-backs on the one used by Home Assistant, including all settings for it.
I also feel reluctant about adding to or changing a syntax that most hass users are already aware of and (to a varying extent) comfortable with.

@Matchlighter
Copy link
Contributor Author

The former isn't an issue since you're already creating a separate Jinja Environment strictly for Lovelace Gen, (jinja = jinja2.Environment(loader=jinja2.FileSystemLoader("/"))) so any custom symbols would be limited only to Lovelace Gen.
What do you think about making this feature optional via a config parameter?

@lmamakos
Copy link

I was thinking about this same sort of thing myself. I might be clever to have the #lovelace_gen first line in the file carry options to specify the various quoting characters. I think that you can pass in replacements for {{ }}, {% %} and {# #} when the template engine is instantiated.

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

3 participants