File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,24 @@ def render(self, context: dict):
214214 yield from self .render_children (context )
215215
216216
217+ class Context (BaseElement ):
218+ """
219+ Pass additional variables into the context.
220+ The additional context names are namespaced to the current element and its child elements.
221+ It can be helpfull for shadowing or aliasing a name in the context.
222+ This element is required because context is otherwise only set by the render function and the loop-variable of Iierator
223+ """
224+
225+ additional_context : dict = {}
226+
227+ def __init__ (self , * children , ** kwargs ):
228+ self .additional_context = kwargs
229+ super ().__init__ (* children )
230+
231+ def render (self , context ):
232+ return super ().render ({** context , ** self .additional_context })
233+
234+
217235def treewalk (
218236 element : typing .List ,
219237 ancestors : typing .Tuple [BaseElement , ...],
You can’t perform that action at this time.
0 commit comments