Changeset 6673
- Timestamp:
- 11/14/07 15:07:27 (1 year ago)
- Files:
-
- django/trunk/django/template/loader_tags.py (modified) (2 diffs)
- django/trunk/docs/templates.txt (modified) (2 diffs)
- django/trunk/tests/regressiontests/templates/tests.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/loader_tags.py
r6399 r6673 3 3 from django.template.loader import get_template, get_template_from_string, find_template_source 4 4 from django.conf import settings 5 from django.utils.safestring import mark_safe 5 6 6 7 register = Library() … … 27 28 def super(self): 28 29 if self.parent: 29 return self.parent.render(self.context)30 return mark_safe(self.parent.render(self.context)) 30 31 return '' 31 32 django/trunk/docs/templates.txt
r6671 r6673 281 281 the ``{{ block.super }}`` variable will do the trick. This is useful 282 282 if you want to add to the contents of a parent block instead of 283 completely overriding it. 283 completely overriding it. Data inserted using ``{{ block.super }}`` will 284 not be automatically escaped (see the `next section`_), since it was 285 already escaped, if necessary, in the parent template. 284 286 285 287 * For extra readability, you can optionally give a *name* to your … … 299 301 two similarly-named ``{% block %}`` tags in a template, that template's parent 300 302 wouldn't know which one of the blocks' content to use. 303 304 .. _next section: #automatic-html-escaping 301 305 302 306 Automatic HTML escaping django/trunk/tests/regressiontests/templates/tests.py
r6671 r6673 618 618 619 619 # Standard template with no inheritance 620 'inheritance01': ("1{% block first %} _{% endblock %}3{% block second %}_{% endblock %}", {}, '1_3_'),620 'inheritance01': ("1{% block first %}&{% endblock %}3{% block second %}_{% endblock %}", {}, '1&3_'), 621 621 622 622 # Standard two-level inheritance … … 627 627 628 628 # Two-level with no redefinitions on second level 629 'inheritance04': ("{% extends 'inheritance01' %}", {}, '1 _3_'),629 'inheritance04': ("{% extends 'inheritance01' %}", {}, '1&3_'), 630 630 631 631 # Two-level with double quotes instead of single quotes … … 636 636 637 637 # Two-level with one block defined, one block not defined 638 'inheritance07': ("{% extends 'inheritance01' %}{% block second %}5{% endblock %}", {}, '1 _35'),638 'inheritance07': ("{% extends 'inheritance01' %}{% block second %}5{% endblock %}", {}, '1&35'), 639 639 640 640 # Three-level with one block defined on this level, two blocks defined next level … … 642 642 643 643 # Three-level with second and third levels blank 644 'inheritance09': ("{% extends 'inheritance04' %}", {}, '1 _3_'),644 'inheritance09': ("{% extends 'inheritance04' %}", {}, '1&3_'), 645 645 646 646 # Three-level with space NOT in a block -- should be ignored 647 'inheritance10': ("{% extends 'inheritance04' %} ", {}, '1 _3_'),647 'inheritance10': ("{% extends 'inheritance04' %} ", {}, '1&3_'), 648 648 649 649 # Three-level with both blocks defined on this level, but none on second level … … 657 657 658 658 # A block defined only in a child template shouldn't be displayed 659 'inheritance14': ("{% extends 'inheritance01' %}{% block newblock %}NO DISPLAY{% endblock %}", {}, '1 _3_'),659 'inheritance14': ("{% extends 'inheritance01' %}{% block newblock %}NO DISPLAY{% endblock %}", {}, '1&3_'), 660 660 661 661 # A block within another block … … 675 675 676 676 # Two-level inheritance with {{ block.super }} 677 'inheritance20': ("{% extends 'inheritance01' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1 _a3_'),677 'inheritance20': ("{% extends 'inheritance01' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1&a3_'), 678 678 679 679 # Three-level inheritance with {{ block.super }} from parent … … 681 681 682 682 # Three-level inheritance with {{ block.super }} from grandparent 683 'inheritance22': ("{% extends 'inheritance04' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1 _a3_'),683 'inheritance22': ("{% extends 'inheritance04' %}{% block first %}{{ block.super }}a{% endblock %}", {}, '1&a3_'), 684 684 685 685 # Three-level inheritance with {{ block.super }} from parent and grandparent 686 'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1 _ab3_'),686 'inheritance23': ("{% extends 'inheritance20' %}{% block first %}{{ block.super }}b{% endblock %}", {}, '1&ab3_'), 687 687 688 688 # Inheritance from local context without use of template loader
