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

Proper file extension for templates for plugin integration? #457

Closed
josefrcm opened this issue Mar 9, 2021 · 4 comments · Fixed by #458
Closed

Proper file extension for templates for plugin integration? #457

josefrcm opened this issue Mar 9, 2021 · 4 comments · Fixed by #458
Assignees

Comments

@josefrcm
Copy link

josefrcm commented Mar 9, 2021

First of all, let me congratulate you for your work. I'm developing an application with Askama and Rocket, and I'm very happy with the results. However, I recently hit an interesting bump. This was using VS Code as my development environment:

  • As the templates are all HTML, I'm just using .html extension.
  • The HTML formatting plugins don't recognize Askama templates. That means no syntax highlighting, no error detection, and no proper formatting. In fact one plugin completely mangled a few templates and caused my website to crash.
  • As Askama is based on Jinja2, I tried to rename my files as .html.j2 and use a Jinja2 plugin (no Askama plugin seems to exist), and lo and behold, it worked perfectly. Syntax highlighting and proper formatting. The code compiles and runs flawlessly, but...
  • Askama's Rocket responder implementation guesses the content type from the file extension, but .html.j2 is not recognized, so it just returns an empty response! No error message, no nothing, just a totally blank page.

So my question is, how can we fix this? I have a couple ideas:

  • Write a proper Askama plugin with its own file extension, or reuse an existing Jinja2 plugin, even if the two syntaxes don't match perfectly?
  • Fix the responders implementations to strip the last part of the extension from the file name, in case it matches a predefined list.
@vallentin
Copy link
Collaborator

vallentin commented Mar 9, 2021

Thanks for the thorough issue!

I actually do the same and use .html.jinja, for the exact reason you mention. I like the last idea, so if the extension is .j2, .jinja2, or .jinja, then it should ignore that, and get the other extension beforehand, e.g. .html.

It might also be useful to allow ext = "...", even if path = "..." is used. Such that it would be possible to do path = "foo.a.b.c", ext = "html".

@vallentin
Copy link
Collaborator

@josefrcm assuming the merged solution solves your problem, then the issue is now resolved. If you want to try it out before a new version is published, then you can do so, by changing your askama dependency to the following:

[dependencies]
askama = { git = "https://github.com/djc/askama", rev = "7b954cd78800b8730401c4471f2289e2d990444f" }

@josefrcm
Copy link
Author

@vallentin I just tested your solution and it works perfectly, thank you so much for the quick response 😀

@vallentin
Copy link
Collaborator

@josefrcm no problem, happy I could help 😄

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

Successfully merging a pull request may close this issue.

2 participants