-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Support global variables? #35
Comments
Hello, please take a look at the new commit 979c9d6 |
I'm still not sure whether it's a good idea to make those variables generally available to any template you ever render with pongo2 within your application. Imagine you use pongo2 at another unrelated place in your application and you still have these variables registered to these unrelated templates. Wouldn't it be better to have a mechanism to make this variables only available to a subset of templates? I thought about introducing template groups which share common settings and variables. This would allow to create, for example, templates for mails which share a common set of global variables and to create a different set of templates for the web which share a different common set of globals (and other settings we can't imagine yet). |
Will work on that soon by introducing template groups/sets. |
You can now either use set := pongo2.NewSet("our web templates") // The idea behind sets is that you can create another set with other globals and configurations for mail templates or other kind of templates
set.Globals["global_variable"] = "this is a test"
tpl, _ := set.FromFile("....")
out, _ := tpl.Execute(Context{"other_variables": 123})
... More information about the recent change is in the commit message. Please let me know if this works for you. |
This's not working on Pongo2. But this is working very well :)
|
Support global (static) variables across multiple template executions.
See #32 as well.
The text was updated successfully, but these errors were encountered: