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

Features add a globals per template rendering ( e.g. per http request) #50

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

mardiros
Copy link
Contributor

At the moment, while rendering an HTTP request, we can't have globals variable per request.

While rendering templates in framework such as FastAPI, or pyramid, there is a request
object that can be passed to the rendering engine in order to get some request
context, it can render url or access to the current session.

While rendering a template, in classic Jinja2, we can set them while fetching the template,
in a get_template call
for example.

Using JinjaX, I propose that we can pass them with a __globals as we can have other __params already.

I am not sur that the implementation is thread safe but if it works for css or js, it could works for those variable.

@mardiros mardiros mentioned this pull request Apr 15, 2024
@jpsca
Copy link
Owner

jpsca commented Apr 19, 2024

Fantastic! I hadn't realized Jinja could have independent globals per template. I would make some changes, such as updating the globals of cached templates in components.py instead of catalog.py, but I can do that after merging.

Thank you for taking the time to code this feature (and for your patience).

@jpsca jpsca merged commit a4cb3b4 into jpsca:main Apr 19, 2024
3 checks passed
@mardiros mardiros deleted the features/globals branch April 20, 2024 06:33
@mardiros
Copy link
Contributor Author

Hi,
thanks for the merge and for the release.

updating the globals of cached templates in components.py instead of catalog.py

I this this is a good approach !

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 this pull request may close these issues.

2 participants