Umbraco Basics: Templates

Right, so this is simple – thou perhaps not as simple in version 4 as in version 3. Main problem is simply just that the main vidoe tutorial on this only covers v3 – where we are dealing with raw HTML templates, whereas v4 now by default comes with support for .NET MasterPages switched on.

So where as the tutorial tells you that Umbraco templates are completely empty and that you can (must) start from scratch – the new v4 in stead comes with something like the below for default:

<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">

</asp:Content>

So, I thought, well great that makes sense, and proceeded to try and nest another MasterPage below this. Full and nice support for this, but I kept getting this error message:

Cannot find ContentPlaceHolder 'masterContentPlaceHolder' in the master page '/masterpages/Master.master'

So what the heck? Well, of course what I realised (fairly quicly, kinda :0) is that of course these MasterPages are placed inside the Umbraco page engine – which no doubt uses it’s own master page – so you have to realise that you are already in a MasterPage inheritance chain when you define your first base MasterPage.
And what does that mean for us? Well it means that everything has to be wrapped in a Content tag – even from the very first start – to illustrate let me show you my new Base Master and a Home Page template that is nested in this:

<%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %>

<asp:Content  id="MasterContentPlaceHolder" ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head></head>

<body>

<asp:ContentPlaceHolder Id="masterContentPlaceHolder" runat="server"></asp:ContentPlaceHolder>

</body>

</html>

</asp:content>

So note that the above is already nested into the Umbraco engine – hence the need for a <asp:content tag at the base level before you can add any HTML.
And so nested within the above I have my child template for the home page:

<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>

<asp:Content ContentPlaceHolderId="masterContentPlaceHolder" runat="server">

Home page Template Rules!

</asp:Content>

Hope that makes some sense.



Some other useful and worthwhile features include the ability to insert data from your document types and generic Umbraco fields as well. Us the top buttons to do this.
We will return to this in more detail later.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: