aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-builtin-functions/language-function-block.md
blob: 941997a559ad4c46c3696fc098aeb370a7c2ca38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{block} {#language.function.block}
=======

`{block}` is used to define a named area of template source for template
inheritance. For details see section of [Template
Interitance](#advanced.features.template.inheritance).

The `{block}` template source area of a child template will replace the
correponding areas in the parent template(s).

Optionally `{block}` areas of child and parent templates can be merged
into each other. You can append or prepend the parent `{block}` content
by using the `append` or `prepend` option flag with the childs `{block}`
definition. With the {\$smarty.block.parent} the `{block}` content of
the parent template can be inserted at any location of the child
`{block}` content. {\$smarty.block.child} inserts the `{block}` content
of the child template at any location of the parent `{block}`.

`{blocks}'s` can be nested.

**Attributes:**

   Attribute Name    Type    Required   Default  Description
  ---------------- -------- ---------- --------- ---------------------------------------
        name        string     Yes       *n/a*   The name of the template source block

**Option Flags (in child templates only):**

    Name    Description
  --------- -------------------------------------------------------------------------------------------
   append   The `{block}` content will be be appended to the content of the parent template `{block}`
   prepend  The `{block}` content will be prepended to the content of the parent template `{block}`
    hide    Ignore the block content if no child block of same name is existing.
   nocache  Disables caching of the `{block}` content

parent.tpl


    <html>
      <head>
        <title>{block name="title"}Default Title{/block}</title>
        <title>{block "title"}Default Title{/block}</title>  {* short-hand  *}
      </head>
    </html>

      

child.tpl


    {extends file="parent.tpl"} 
    {block name="title"}
    Page Title
    {/block}

      

The result would look like


    <html>
      <head>
        <title>Page Title</title>
      </head>
    </html>

parent.tpl


    <html>
      <head>
        <title>{block name="title"}Title - {/block}</title>
      </head>
    </html>

      

child.tpl


    {extends file="parent.tpl"} 
    {block name="title" prepend}
    Page Title
    {/block}

      

The result would look like


    <html>
      <head>
        <title>Title - Page Title</title>
      </head>
    </html>

parent.tpl


    <html>
      <head>
        <title>{block name="title"} is my title{/block}</title>
      </head>
    </html>

      

child.tpl


    {extends file="parent.tpl"} 
    {block name="title" append}
    Page Title
    {/block}

      

The result would look like


    <html>
      <head>
        <title>Page title is my titel</title>
      </head>
    </html>

parent.tpl


    <html>
      <head>
        <title>{block name="title"}The {$smarty.block.child} was inserted here{/block}</title>
      </head>
    </html>

      

child.tpl


    {extends file="parent.tpl"} 
    {block name="title"}
    Child Title
    {/block}

      

The result would look like


    <html>
      <head>
        <title>The Child Title was inserted here</title>
      </head>
    </html>

parent.tpl


    <html>
      <head>
        <title>{block name="title"}Parent Title{/block}</title>
      </head>
    </html>

      

child.tpl


    {extends file="parent.tpl"} 
    {block name="title"}
    You will see now - {$smarty.block.parent} - here
    {/block}

      

The result would look like


    <html>
      <head>
        <title>You will see now - Parent Title - here</title>
      </head>
    </html>

See also [Template
Inheritance](#advanced.features.template.inheritance),
[`$smarty.block.parent`](#language.variables.smarty.block.parent),
[`$smarty.block.child`](#language.variables.smarty.block.child), and
[`{extends}`](#language.function.extends)