Chapter 4 focuses on the creation and management of the templates themselves. This section discusses the practical application of those templates and how managing templates correctly can make for a very flexible presentation engine.
In most cases a document type has a one-to-one relationship with a template. By default, this is the case when you create a document type and elect to have a template created as part of the process. What you may not know is that any given document type can have any number of associated templates, as shown in Figure 8-4.
Several reasons exist for this feature:
So, when you create your templates, make sure to take into account the various page types that they need to support. One example of when to share a document type with two templates is for toggling a feature of a page. To illustrate the point, follow these steps:
LISTING 8-1: RunwayTextpage+Sidebar.master
<%@ Master Language=“C#” MasterPageFile=“~/masterpages/RunwayMaster.master” AutoEventWireup=“true” %> <asp:Content ContentPlaceHolderID=“RunwayMasterContentPlaceHolder” runat=“server”> <div id=“content”> <umbraco:Macro Alias=“SiteBreadcrumb” runat=“server”></umbraco:Macro> <div id=“contentHeader”> <h2><umbraco:Item runat=“server” field=“pageName”/></h2> </div> <umbraco:Item runat=“server” field=“bodyText” /> </div> <div id=“subNavigation”> <umbraco:Item runat=“server” field=“sidebarContent” /> </div> </asp:Content>
What you have done so far is to extend the functionality of the text page document type and add a template to support the new sidebar feature. To see this feature in action, you can change one of the pages in the content tree and check out the result as described in the following steps. When you view the details of any content page in the content tree, you can now see the added Sidebar Content field, as shown in Figure 8-8.
A tip text snippet was added in this example to remind editors that they must select the appropriate template when utilizing the Sidebar Content field.
You can programmatically achieve similar results with a single template by inserting a macro that checks the length of the sidebarContent field and injects some strategically placed CSS to remove the sidebar container when no content exists. These methods are outside the scope of this book.