You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 14/umbraco-cms/fundamentals/design/templates/README.md
+76-40
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,46 @@
1
1
---
2
-
description: Templating in Umbraco including inheriting from master template
2
+
description: Templating in Umbraco builds on the concept of Razor Views from ASP.NET MVC.
3
3
---
4
4
5
5
# Templates
6
6
7
-
_Templating in Umbraco builds on the concept of Razor Views from ASP.NET MVC - if you already know this, then you are ready to create your first template - if not, this is a quick and handy guide._
7
+
Templates are the files that control the look and feel of the frontend of your Umbraco websites. Building on the concept of MVC Razor Views, template files enable you to structure your websites using HTML, CSS, and JavaScript. When tied to a Document Type, templates are used to render your Umbraco content on the frontend.
8
8
9
-
## Creating your first Template
9
+
You can manage and work with your templates directly from the Settings section in the Umbraco backoffice. Each Template can also be found as a `cshtml` file in the `Views` folder in your project directory.
10
10
11
-
By default, all document types should have a template attached - but in case you need an alternative template or a new one, you can create one:
11
+
## Creating Templates
12
+
13
+
When building an Umbraco website you can automatically generate Templates when you create a new Document Type. This will ensure the connection between the two and you can jump straight from defining the content to structuring it.
14
+
15
+
Choose the option called **[Document Type with Template](../../data/defining-content/README.md)** when you create a new Document Type to automatically create a Template as well.
16
+
17
+
In some cases, you might want to create independent Templates that don't have a direct connection to a Document Type. You can follow the steps below to create a new blank Template:
12
18
13
19
1. Go to the **Settings** section inside the Umbraco backoffice.
14
20
2. Click **...** next to the **Templates** folder.
15
21
3. Choose **Create**.
16
22
4. Enter a template name.
17
-
5. Click the **Save** button. You will now see the default template markup in the backoffice template editor.
23
+
5. Click the **Save** button.
24
+
25
+
You will now see the default template markup in the backoffice template editor.
18
26
19
27

20
28
21
29
## Allowing a Template on a Document Type
22
30
23
-
To use a template on a document, you must first allow it on the content's type. Open the Document Type you want to use the template, go to the Templates tab and select the template under the **Allowed Templates** section.
31
+
To use a Template on your content, you must first allow it on the content Document Type.
32
+
33
+
1. Open the Document Type you want to use the template.
34
+
2. Open the **Templates** Workspace View.
35
+
3. Select your Template under the **Allowed Templates** section.
24
36
25
37

26
38
27
-
## Inheriting a Master Template
39
+
## Inheriting a Template
40
+
41
+
A Template can inherit content from a "Master Template". This is done by using the ASP.NET views Layout feature.
28
42
29
-
A template can inherit content from a master template by using the ASP.NET views Layout feature. Let's say we have a template called **MasterView**, containing the following HTML:
43
+
Let's say you have a Template called **MainView**, containing the following HTML:
When a page using the textpage template renders, the final HTML will be merged replacing the `@renderBody()` placeholder, and produce the following:
84
+
When a page that uses a Template with a Master Template defined is rendered, the HTML of the two templates is merged.
85
+
86
+
The code from the Template replaces the `@RenderBody()` tag in the Master Template. Following the examples above, the final HTML will look like the code in the snippet below:
60
87
61
88
```csharp
62
89
@inheritsUmbraco.Web.Mvc.UmbracoViewPage
@@ -72,17 +99,39 @@ When a page using the textpage template renders, the final HTML will be merged r
What's good to know, is that you are not limited to a single section. Template sections allow child templates that inherit the master layout template to insert HTML code up into the main layout template. For example, a child template inserting code into the `<head>` tag of the master template.
0 commit comments