@@ -99,11 +99,11 @@ The code from the Template replaces the `@RenderBody()` tag in the Master Templa
99
99
< / html >
100
100
```
101
101
102
- ## Template Sections
102
+ ## Named Sections
103
103
104
104
Template Sections give you added flexibility when building your templates . Use the Template Section together with a Master Template setup , to decide where sections of content is placed .
105
105
106
- If a Child Template needs to add code to the `<head >` tag a Section must be defined and then used in the Master Template . This is made possible by [Named Sections ](https :// www.youtube.com/watch?v=lrnJwglbGUA).
106
+ If a Child Template needs to add code to the `<head >` tag a Section must be defined and then used in the Master Template . This is made possible by [Named Sections ](https :// www.youtube.com/watch?v=lrnJwglbGUA).
107
107
108
108
The following steps will guide you through defining and using a Named Section :
109
109
@@ -112,23 +112,26 @@ The following steps will guide you through defining and using a Named Section:
112
112
3 . Choose ** Define a named section ** .
113
113
4 . Give the section a name and click ** Submit ** .
114
114
115
- On your child page template call `@section Head {}` and then type your markup that will be pushed into the Master Template :
115
+ ! [Define a named section by giving it a name ](images / defined - named - section .png )
116
+
117
+ The following code will be added to your Template :
116
118
117
119
```csharp
118
- @section Head {
119
- < style >
120
- body {
121
- background : #ff0000 ;
122
- }
123
- < / style >
120
+ @section SectionName {
121
+
124
122
}
125
123
```
126
124
127
- ```csharp
128
- @RenderSection (" SectionName" )
129
- ```
125
+ 5 . Add whichever code you need between the curly brackets .
126
+ 6 . Save the changes .
127
+ 7 . Open the Master Template .
128
+ 8 . Choose a spot for the section , and set the cursor there .
129
+ 9 . Select the ** Sections ** option .
130
+ 10 . Choose ** Render a named section ** .
131
+ 11 . Enter the name of the section you want to add .
132
+ 12 . Click ** Submit ** .
130
133
131
- For instance , if you want to be able to add HTML to your `< head > ` tags write :
134
+ For instance , if you want to be able to add HTML to your `< head > ` tags , you would add the tag there :
132
135
133
136
```csharp
134
137
@inherits Umbraco .Web .Mvc .UmbracoViewPage
@@ -139,23 +142,26 @@ For instance, if you want to be able to add HTML to your `<head>` tags write:
139
142
< html >
140
143
< head >
141
144
< title > Title < / title >
142
- @RenderSection (" Head " )
145
+ @RenderSection (" SectionName " )
143
146
< / head >
144
147
145
148
< body >
146
149
< / body >
147
150
< / html >
148
151
```
149
152
150
- By default , when rendering a named section , the section is not mandatory . To make the section mandatory , add `true ` or enable ** Section is mandatory ** field in the **Sections ** option .
153
+ You can decide whether a section should be mandatory or not . Making a section mandatory means that any templates using the Master Template is required to have the section defined .
154
+
155
+ To make the section mandatory , you have two options :
156
+
157
+ * Check the ** Section is mandatory ** field when using the **Sections** dialog in the backoffice.
158
+ * Add `true ` to the code tag like shown in the example below .
151
159
152
160
```csharp
153
161
@RenderSection (" Head" , true )
154
162
```
155
163
156
- 
157
-
158
-
164
+ 
159
165
160
166
## Injecting Partial Views
161
167
@@ -186,9 +192,3 @@ The created partial view can now be injected into any template by using the `@Ht
186
192
### Tutorials
187
193
188
194
* [Creating a basic website with Umbraco ](.. / .. / .. / tutorials / creating - a - basic - website / )
189
-
190
- ### Umbraco Learning Base
191
-
192
- {% embed url = " https://www.youtube.com/playlist?ab_channel=UmbracoLearningBase&list=PLgX62vUaGZsFmzmm4iFKeL41CZ5YFw09z" % }
193
- Playlist : Templates in Umbraco
194
- {% endembed % }
0 commit comments