Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 37 lines (21 sloc) 0.966 kb
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
1 .. highlight:: django
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
2 .. index:: tag; block
3 .. _tag-block:
4
5 block
6 =====
7
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
8 Define a block in a template and overrules a block from an inherited template.
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
9
10 The `block` tag is used for replacing blocks in inherited templates.
11
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
12 For example, when we have a template `base.tpl`, in which we define a block called `name`::
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
13
14 Hello {% block name %}my{% endblock %} world.
15
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
16 And we define a second template, `page.tpl`, which :ref:`tag-extends` the first template::
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
17
18 {% extends "base.tpl" %}
19 {% block name %}Peter's{% endblock %}
20
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
21 Then the result of rendering `page.tpl` will be::
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
22
23 Hello Peter's world.
24
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
25 If we do not include the block definition, so `page.tpl` just contains the :ref:`tag-extends` tag::
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
26
27 {% extends "base.tpl" %}
28
29 then the output will be::
30
31 Hello my world.
32
36813f5 Arjan Scherpenisse doc: Finalize initial docs on tags.
arjan authored
33 The name of a block must be a valid identifier, consisting of
34 alphanumeric characters (a-z, 0-9) and the underscore charater.
47ef7b4 Andreas Stenius doc: migrated docs for a few tags.
kaos authored
35
36 .. seealso:: :ref:`tag-extends` and :ref:`tag-overrules`.
Something went wrong with that request. Please try again.