- The <%page args> tag can now be used in a base inheriting template - the full set of render() arguments are passed down through the inherits chain. Undeclared arguments go into **pageargs as usual. [ticket:116]
diff --git a/CHANGES b/CHANGES index b490f90..2de917e 100644 --- a/CHANGES +++ b/CHANGES
@@ -32,6 +32,12 @@ - Template accepts empty control structure, i.e. % if: %endif, etc. [ticket:94] + +- The <%page args> tag can now be used in a base + inheriting template - the full set of render() + arguments are passed down through the inherits + chain. Undeclared arguments go into **pageargs + as usual. [ticket:116] 0.2.6
diff --git a/mako/runtime.py b/mako/runtime.py index 19d79de..f59a8bc 100644 --- a/mako/runtime.py +++ b/mako/runtime.py
@@ -314,6 +314,7 @@ def _include_file(context, uri, calling_uri, **kwargs): """locate the template from the given uri and include it in the current output.""" + template = _lookup_template(context, uri, calling_uri) (callable_, ctx) = _populate_self_namespace(context._clean_inheritance_tokens(), template) callable_(ctx, **_kwargs_for_callable(callable_, context._orig, **kwargs)) @@ -377,7 +378,7 @@ context = Context(buf, **data) context._outputting_as_unicode = as_unicode context._with_template = template - _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data)) + _render_context(template, callable_, context, *args, **data) return context._pop_buffer().getvalue() def _kwargs_for_callable(callable_, data, **kwargs):
diff --git a/test/test_template.py b/test/test_template.py index 204ee3b..c738012 100644 --- a/test/test_template.py +++ b/test/test_template.py
@@ -369,7 +369,60 @@ assert False except TypeError, e: assert True + + def test_inherits(self): + lookup = TemplateLookup() + lookup.put_string("base.tmpl", + """ + <%page args="bar" /> + ${bar} + ${pageargs['foo']} + ${self.body(**pageargs)} + """ + ) + lookup.put_string("index.tmpl", """ + <%inherit file="base.tmpl" /> + <%page args="variable" /> + ${variable} + """) + self._do_test( + lookup.get_template("index.tmpl"), + "bar foo var", + filters=flatten_result, + template_args={'variable':'var', 'bar':'bar', 'foo':'foo'} + + ) + + def test_includes(self): + lookup = TemplateLookup() + lookup.put_string("incl1.tmpl", + """ + <%page args="bar" /> + ${bar} + ${pageargs['foo']} + """ + ) + lookup.put_string("incl2.tmpl", + """ + ${pageargs} + """ + ) + lookup.put_string("index.tmpl", """ + <%include file="incl1.tmpl" args="**pageargs"/> + <%page args="variable" /> + ${variable} + <%include file="incl2.tmpl" /> + """) + + self._do_test( + lookup.get_template("index.tmpl"), + "bar foo var {}", + filters=flatten_result, + template_args={'variable':'var', 'bar':'bar', 'foo':'foo'} + + ) + def test_with_context(self): template = Template(""" <%page args="x, y, z=7"/>