Skip to content

Instantly share code, notes, and snippets.

@loic
Created August 30, 2013 04:26
Show Gist options
  • Save loic/6386313 to your computer and use it in GitHub Desktop.
Save loic/6386313 to your computer and use it in GitHub Desktop.
diff --git a/tests/template_tests/templates/recursive_include.html b/tests/template_tests/templates/recursive_include.html
new file mode 100644
index 0000000..fdc7702
--- /dev/null
+++ b/tests/template_tests/templates/recursive_include.html
@@ -0,0 +1,7 @@
+"Recursion!"
+{% for comment in comments %}
+ {{ comment.comment }}
+ {% if comment.children %}
+ {% include "recursive_include.html" with comments=comment.children %}
+ {% endif %}
+{% endfor %}
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index e9c0a0f..deb6a2e 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -1852,3 +1852,22 @@ class RequestContextTests(unittest.TestCase):
# The stack should now contain 3 items:
# [builtins, supplied context, context processor]
self.assertEqual(len(ctx.dicts), 3)
+
+
+class RecursiveIncludesTests(unittest.TestCase):
+ def test(self):
+ comments = [
+ {
+ 'comment': 'A1',
+ 'children': [
+ {'comment': 'B1', 'children': []},
+ {'comment': 'B2', 'children': []},
+ {'comment': 'B3', 'children': [
+ {'comment': 'C1', 'children': []}
+ ]},
+ ]
+ }
+ ]
+
+ t = loader.get_template('recursive_include.html')
+ print t.render(Context({'comments': comments})).replace(' ', '').replace('\n', ' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment