@@ -150,3 +150,50 @@ def do_include(parser, token):
150
150
extra_context = namemap ,
151
151
isolated_context = isolated_context ,
152
152
)
153
+
154
+ def visit_extends (self , node , frame ):
155
+ """This method overrides the jinja extends tag
156
+ Is called as part of the compiler CodeGenerator
157
+ and adds a line to use the template_new_context as
158
+ part of the runtime render to pull in the dpl context
159
+ Handles visiting extends
160
+ """
161
+ from .monkey_utils import jinja_visit_Extends
162
+
163
+ jinja_visit_Extends (self , node , frame )
164
+ # addition to update the context with dpl context
165
+ # calls the template_new_context method below when
166
+ # invoked at runtime
167
+ self .writeline (
168
+ "parent_template.new_context(context.get_all(), True,"
169
+ f" { self .dump_local_context (frame )} )"
170
+ )
171
+
172
+
173
+ def template_new_context (
174
+ self ,
175
+ vars = None ,
176
+ shared = False ,
177
+ locals = None ,
178
+ ):
179
+ """This method overrides the jinja include tag
180
+ Is called as part of Template.render by jinja2 and is updated
181
+ to pull in the dpl context
182
+ Create a new :class:`Context` for this template. The vars
183
+ provided will be passed to the template. Per default the globals
184
+ are added to the context. If shared is set to `True` the data
185
+ is passed as is to the context without adding the globals.
186
+
187
+ `locals` can be a dict of local variables for internal usage.
188
+ """
189
+ from jinja2 .runtime import new_context
190
+
191
+ if is_pattern_library_context (vars or {}) and (
192
+ pattern_context := get_pattern_context (self .name )
193
+ ):
194
+ for k , v in pattern_context .items ():
195
+ vars .setdefault (k , v )
196
+
197
+ return new_context (
198
+ self .environment , self .name , self .blocks , vars , shared , self .globals , locals
199
+ )
0 commit comments