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

[Feature Request] Custom global environment for Jinja2? #195

Closed
nc7s opened this issue May 20, 2023 · 1 comment
Closed

[Feature Request] Custom global environment for Jinja2? #195

nc7s opened this issue May 20, 2023 · 1 comment

Comments

@nc7s
Copy link

nc7s commented May 20, 2023

Is your feature request related to a problem? Please describe your use case.

I have a config object that I'd like to pass to all templates.

Currently I have to dig into the source and figure out a workaround like this:

app.ext.environment.globals.update({ 'config': config })

Describe the solution you'd like

A configuration point like:

from sanic import Sanic

app = Sanic(__name__)
app.config.templating_globals = { 'config': config }
# or
app.config.templating_environment.globals.update({ 'config': config })

Will PR myself, but want to ask for input first.

@ahopkins
Copy link
Member

That is the intended pattern, and not a workaround. It probably could be documented better.

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