Adding frame variables from custom tag
See original GitHub issueI’m trying to make an extension which adds support for the trans
tag. Jinja trans
syntax requires you to bind template expressions to new variables via keyword arguments, like:
<p>{% trans user=user.username %}Hello {{ user }}!{% endtrans %}</p>
Now, I’m able to iterate over the arguments to my tag and add them to the context like this:
this.run = function(context, args, body) {
for (key in args) {
context.ctx[key] = args[key];
}
return gettext(body()); # gettext() is defined somewhere else.
}
But it seems I’m getting the global context and polluting this, which leaves my new variables available outside my trans
tag (i.e. the user
variable will be available everywhere afterwards).
How do I extend only the “local” context used by my tag? It seems the for
and (in some cases) set
tags do this and I tried looking through the source for this, but I’m unfortunately lost.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Create data.frame with variable as tag - Stack Overflow
frame (colname=1:11) by providing variable x="colname" , I've tried data.frame(as.formula("x=1:11")) but id does not work, what is tag in data ...
Read more >Chapter 8 Custom Tags in JSP Pages (The Java EE 5 Tutorial)
Declaring Tag Variables in Tag Files. Tag attributes are used to customize tag behavior much as parameters are used to customize the behavior...
Read more >Custom tag variables - Adobe Support
A custom tag can set a Caller variable to provide information to the caller. Set the Caller variable as follows: ...
Read more >[Guide] ElvUI Custom Tag Guide - Tukui
Custom Texts - This will allow you to create new element to add custom text to your frame. Element Selection - You can...
Read more ><iframe>: The Inline Frame element - HTML - MDN Web Docs
The <iframe> HTML element represents a nested browsing context, embedding another HTML page into the current one. Try it. HTML Demo: <iframe>.
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 Free
Top 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
Hi all, guys! Just faced the same kind of problem. I’m creating format.js internationalization helper for nunjucks templater. And one last thing i have to implement — is a custom ‘intl’ tag, that overrides global intl locale options provided. For ex., you can render whole template, using a ‘en’ locale, but have one block with ‘fr’ locale. Unfortunately, docs about hijacking nunjucks extensions api is very poor, but i’ve got somehow through sources, and have come to this.
What about adding access to frame stack through some method in ctx, like lookup? For example:
Or just allow raw access to frames stack, so developer can use push/pop and all other frame methods.
+1