| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | # {block}
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | `{block}` is used to define a named area of template source for template | 
					
						
							|  |  |  | inheritance. For details see section of [Template | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md). | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | The `{block}` template source area of a child template will replace the | 
					
						
							| 
									
										
										
										
											2022-10-22 22:08:38 +02:00
										 |  |  | corresponding areas in the parent template(s). | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | Optionally `{block}` areas of child and parent templates can be merged | 
					
						
							|  |  |  | into each other. You can append or prepend the parent `{block}` content | 
					
						
							| 
									
										
										
										
											2022-10-22 22:08:38 +02:00
										 |  |  | by using the `append` or `prepend` option flag with the child's `{block}` | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | definition. With `{$smarty.block.parent}` the `{block}` content of | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | the parent template can be inserted at any location of the child | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | `{block}` content. `{$smarty.block.child}` inserts the `{block}` content | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | of the child template at any location of the parent `{block}`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | `{blocks}'s` can be nested. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ## Attributes
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | | Attribute Name | Required | Description                                                                                                          | | 
					
						
							|  |  |  | |----------------|----------|----------------------------------------------------------------------------------------------------------------------| | 
					
						
							|  |  |  | | name           | yes      | The name of the template source block                                                                                | | 
					
						
							|  |  |  | | assign         | no       | The name of variable to assign the output of the block to. | | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | > **Note** 
 | 
					
						
							|  |  |  | >  | 
					
						
							|  |  |  | > The assign attribute only works on the block that actually gets executed, so you may need 
 | 
					
						
							|  |  |  | > to add it to each child block as well.
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ## Option Flags (in child templates only):
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | | Name    | Description                                                                             | | 
					
						
							|  |  |  | |---------|-----------------------------------------------------------------------------------------| | 
					
						
							|  |  |  | | append  | The `{block}` content will 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                                               | | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ## Examples
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | parent.tpl | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>{block name="title"}Default Title{/block}</title> | 
					
						
							|  |  |  |         <title>{block "title"}Default Title{/block}</title>  {* short-hand  *} | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | child.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {extends file="parent.tpl"}  | 
					
						
							|  |  |  |     {block name="title"} | 
					
						
							|  |  |  |     Page Title | 
					
						
							|  |  |  |     {/block} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The result would look like | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>Page Title</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | parent.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>{block name="title"}Title - {/block}</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | child.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {extends file="parent.tpl"}  | 
					
						
							| 
									
										
										
										
											2023-01-31 11:23:50 +01:00
										 |  |  |     {block name="title" append} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |         Page Title | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {/block} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The result would look like | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>Title - Page Title</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | parent.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>{block name="title"} is my title{/block}</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | child.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {extends file="parent.tpl"}  | 
					
						
							| 
									
										
										
										
											2023-01-31 11:23:50 +01:00
										 |  |  |     {block name="title" prepend} | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     Page Title | 
					
						
							|  |  |  |     {/block} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The result would look like | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>Page title is my titel</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | parent.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>{block name="title"}The {$smarty.block.child} was inserted here{/block}</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | child.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {extends file="parent.tpl"}  | 
					
						
							|  |  |  |     {block name="title"} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |         Child Title | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {/block} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  |       | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | The result would look like | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>The Child Title was inserted here</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | parent.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>{block name="title"}Parent Title{/block}</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |        | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | child.tpl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```smarty | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {extends file="parent.tpl"}  | 
					
						
							|  |  |  |     {block name="title"} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |         You will see now - {$smarty.block.parent} - here | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     {/block} | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  |       | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | The result would look like | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     <html> | 
					
						
							|  |  |  |       <head> | 
					
						
							|  |  |  |         <title>You will see now - Parent Title - here</title> | 
					
						
							|  |  |  |       </head> | 
					
						
							|  |  |  |     </html> | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | See also [Template | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md), | 
					
						
							|  |  |  | [`$smarty.block.parent`](../language-variables/language-variables-smarty.md#smartyblockparent-languagevariablessmartyblockparent), | 
					
						
							|  |  |  | [`$smarty.block.child`](../language-variables/language-variables-smarty.md#smartyblockchild-languagevariablessmartyblockchild), and | 
					
						
							|  |  |  | [`{extends}`](./language-function-extends.md) |