Access to a the templating context object in global functions
See original GitHub issueJust like #109, It would be quite useful to have access to the render context object inside global functions.
A use case:
I have a CMS system and I need a function which returns the url for content. The code bellow should work, as it works if it were a filter.
env.addGlobal("urlFor", function (content) {
return this.ctx.baseUrl + "/" + content.slug;
});
Thanks
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Variables and functions available to templates — CKAN 2.9.7 ...
To see which additional global variables and context attributes are available to a given template, use CKAN's debug footer. Any variables explicitly passed ......
Read more >Global objects — Jinja Documentation
This section covers the behavior of global objects in the Jinja namespace and also the ... But what if you want to access...
Read more >Accessing the context (or the root object) passed to Handler.js ...
1 Answer 1 · In the template I have an <input type="button"/> in the end. · So you're saying that the user should...
Read more >Global Variables in Flask Templates Using Context Processors
In this video I'll show you how to pass global variables and functions to all of your templates in Flask using context processors....
Read more >JavaScript Global Object | Contentful
The global object in JavaScript is an always defined object that provides variables and functions, and is available anywhere. In a web browser, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In general, nunjucks doesn’t intend to support untrusted template authors. There are too many ways for a malicious template author to at the very least DoS the system.
That said, I’m not sure either why settings are stored on the context. Convenience maybe?
here is what the object looks like,
I was more focused, on the
view
method, they can serve a different view with a bit of hacking.but what’s to say you leave that on, forget all about it, and one day
nunjucks
, decides to extend the settings object to include more sensitive information, the context should display the settings period (as a principal).I mean security wise, you do not want to expose anything you have explicitly decide to do so.