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

Document template inheritance block naming restrictions #1090

Open
malteneuss opened this issue Aug 30, 2024 · 2 comments
Open

Document template inheritance block naming restrictions #1090

malteneuss opened this issue Aug 30, 2024 · 2 comments

Comments

@malteneuss
Copy link
Contributor

malteneuss commented Aug 30, 2024

I just stumbled upon an unexpected quirk where apparently hyphens are not allowed in template block names:

<html lang="en">
  <head>
    {% block a-head %}{% endblock %}
  </head>
</html>

results in a vague error like

error: problems parsing template source at row 7, column 15 near:
       "head %}\n..."
  --> website/src/routes.rs:12:10
   |
12 | #[derive(Template)]

while {% block head %} works as expected. I would like to document the naming restrictions if someone knows them or could point me to source code that parses such expressions.

@djc
Copy link
Owner

djc commented Sep 2, 2024

Thanks for the report. The parser lives here:

https://github.com/djc/askama/blob/main/askama_parser/src/node.rs#L778

Some documentation would be great -- we could also consider relaxing the grammar it accepts, assuming that doesn't add too much complexity.

@malteneuss
Copy link
Contributor Author

malteneuss commented Sep 7, 2024

Thanks for the hint. Skimming through the code i found out that "identifier" is the function that restricts the names to alphabetic characters only (by delegating to https://docs.rs/nom/latest/src/nom/traits.rs.html#246). As identifier is used quite often in https://docs.rs/nom/latest/src/nom/traits.rs.html#246 for many Node types, i wouldn't add a naming hint for blocks only; and i wouldn't want to duplicate the same hint for almost all Node types in the book.
=> The best solution would be to allow the same names as Rust allows (as for top-level variables) if possible. Unfortunately, i don't consider myself knowledgeable enough to implement that. Feel free to close this issue, if there's other more urgent work.

@djc djc changed the title Document template inheritence block naming restrictions Document template inheritance block naming restrictions Sep 9, 2024
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