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

Jinja Integration #165

Open
ZeroIntensity opened this issue May 5, 2024 · 0 comments
Open

Jinja Integration #165

ZeroIntensity opened this issue May 5, 2024 · 0 comments
Labels
advanced This should only be looked at by someone who knows what they're doing api This has to do with the Python API (view) delayed Delayed due to another issue feature New feature

Comments

@ZeroIntensity
Copy link
Owner

Proposal:

Jinja2 is quite popular when it comes to Python templating. It lets you integrate Python into your HTML with syntax that looks kind of like:

<p>Hello, {{ world }}</P>

Personally, I don't think this syntax is very pretty - but that's not really up for me to decide. Jinja support was added in #126. However, theoretically, with some black magic at runtime, Python code itself could be used to take Jinja variables. This could integrate nicely with #12, whenever that gets done.

I'm thinking it could look something like:

from view import get, jinja_vars
from view.components import *

scope = jinja_vars()

@get("/")
async def index():
    return p(f"Hello, {scope.world}!")

This could then be used from Jinja templates, somehow:

env.render_template("app/index.py")  # Very speculative, I'm not sure if Jinja would even allow this

This feature would allow for some nice, easy integration with tools that require Jinja, such as MkDocs. If doing it through render_template isn't possible, maybe Jinja has some way to call Python files, and view.py could mess around with the stack to get the scope?

@ZeroIntensity ZeroIntensity added feature New feature advanced This should only be looked at by someone who knows what they're doing api This has to do with the Python API (view) delayed Delayed due to another issue labels May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advanced This should only be looked at by someone who knows what they're doing api This has to do with the Python API (view) delayed Delayed due to another issue feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant