Umbraco Manual 7.1 - How To Create An Umbraco Website From Flat HTML Files
Umbraco Manual 7.1 - How To Create An Umbraco Website From Flat HTML Files
uk
Revision History
We avoid using one of the starter kits as when it comes to building your own site these dont give you an
understanding of the basics of Umbraco Document Types and Templates and how these work together to
build pages.
A clean, empty installation of Umbraco e.g. no starter site installed, see the notes below what to
do when running through the installation wizard. Use the latest main 7.X download. Follow the
installation steps in the documentation http://our.umbraco.org/documentation/Installation
A copy of Initializr a HTML5, responsive template which is a nice start for any website.
https://github.com/verekia/initializr-template/archive/master.zip if you prefer you can use your own
flat HTML files but my examples will use this.
3 Getting Started
If you can see the Umbraco Starter kit site youve missed the option to install Umbraco with no starter site.
You need to reinstall Umbraco if you can see the starter kit if you did a manual install you can delete all
files in the directory where your local host is being served from, copy the Umbraco zip contents back in and
then hit localhost.
Log into your Umbraco installation (e.g. go to http://localhost/umbraco in your browser). You should be
faced with an empty Umbraco installation but where to start!?
4 Document Types
Document Types are infinitely extendable but usually youll add data fields something like the following:
Page title
Sub Heading
Body Text
Meta Title
Meta Description
...
Each Data Field has a type - e.g. a text string or a number or rich text body... well come to this later.
2. Document Types is strangely positioned as the last option in the list yet its always the starting
point for any Umbraco build. Hover over the Document Types node and youll see three dots ... ,
click this to see the menu. Then click + Create button.
3. Ignore the Master Document Type drop down for now. Give our new Document Type the Name
= HomePage and ensure the Create matching template checkbox is checked. Click Create.
4. Umbraco now adds a Document Type to the tree under the node. Youll see four tabs Info,
Structure, Generic properties, Tabs. Click Info (should already be selected) and then the
Choose... link next to the Icon label. Enter home into the search and you'll have a house icon
this will help our editors in the Content tree later.
5. Enter in the Description field This is our homepage template. This text is used to help the user
select the correct document type later.
6. Next click the Structure tab and check Allow at root. This will allow us to create a homepage at
the root (simple huh?).
7. Next we go to the Tabs tab. Create a new tab called Contents and then another called Footer
(enter the name and click the New tab button remembering to click Save after).
8. Now go to the Generic properties this tab is where we create the data containers that the
homepage will need and use. Click on the link Click here to add a new property. Enter the
Name Page Title. When you move to the next field youll see Umbraco helpfully gives you the alias
pageTitle. The Type is defaulted to Textstring and Tab = Contents (remember, we just
created that!). Description again helps the editor so well fill this in The main title of the page
(e.g. Welcome to Widgets Ltd).
9. Ignore the rest of the fields for now and click the green Save button at the top right.
10. Repeat this step, clicking the Click here to add a new property link at the top of the Generic
Properties tab and create these (remembering to click Save each time):
Alias: bodyText
Tab: Contents
Alias: footerText
Type: Textstring
11. You should now have a Generic Properties tab that looks like this:
Weve now created our first Document Type Umbraco needs three things to create a webpage and this is
the first and most important. It takes the data inside an instance of the Document Type and merges it with
a template well edit our template next.
NOTE in early versions of 7.1 the tree doesnt automatically refresh to show you this, if its missing
try a hard refresh of Umbraco (Ctrl+F5) should be fixed soon.
Clicking on the Homepage node will load the template which, except for a little bit of Razor code,
is empty!
2. Leaving the code thats there (if you dont understand it, dont worry!) lets copy our template code
in. Open up index.html from the Initializr template in your favourite text editor (Notepad++ is
good). Copy and paste the whole thing into this template **after** the closing curly brace }. Your
template should now look like below:
We now have a template. Thats two out of the three stages complete for our first page.
1. Were now ready to create our first page in Umbraco! Click the Content button (first option in the
left hand menu).
2. Hover over the grey text CONTENT and youll see the three dots ... click this. If youve done
everything correctly so far you should see the option to create our Homepage!
If you cant see this then dont panic check that Settings> Document Types > Homepage
node > Structure tab > Allow at root is checked.
3. Lets create our homepage. Click the icon and youll see what weve just been setting up our
document type is now going to drive our homepage content it gives us and the editors the fields
they need.
4. In red at the top youll see Enter a name... click this and enter a name (on some browsers this is
hard to see as a field an Umbraco bug has been raised for this). Were going to call this
Homepage.
6. Now click the green Save and publish button. The menu will reload with our homepage node
under the CONTENT label. And heres the good bit... go and refresh your webpage in your browser
http://localhost the default Umbraco page will be gone and well see a very bare, unstyled page!
Were getting there!
NOTE you could use the Umbraco UI to create your CSS file. Settings > Stylesheets > ... > +
Create and create a stylesheet called style (dont add the file suffix .css) and paste the CSS in I find
it easier to copy the CSS. Using either method should be noted does NOT include them in your HTML
markup automatically Umbraco produces clean output and this means you only wire up what you
want and need.
NOTE you can also use the UI interface to create your JS files too Settings > Scripts > ... > +
Create (again dont add the suffix but select .js from the Type dropdown) the reference in your
template should be scripts/myfile.js.
3. Now in dev tools when looking at the http://localhost page you should find that the network tab
doesnt report any missing assets - if it does have a look and fix any typos / check the files are in the
right places!
Weve marked in blue where we want our data field content to be output. Now we need to wire up the
relevant fields.
1. Go to the Settings > Templates > Homepage. Scroll down and highlight the text h1#title
around line 27.
2. Click the button Insert Umbraco Page Field and under the Choose field drop down select
pageTitle from the Custom Fields section.
4. Next do the same for the content between the <header></header> tags (around lines 42 -43)
using field bodyText. Again click the Insert and then Save buttons.
5. Finally we do the footer between the <h3></h3> tags in the footer div (line 68).
6. Now go and reload your homepage... viola! We have content! Now, we could go back and add two
tabs called Article1, Article 2, Article Footer each containing a title and content field and wire these to
the relevant places in the template. However this would limit the content manager to always having
to have these sections. This might be OK but we could also use child nodes well learn about those
later.
Umbraco provides us with an elegant solution to keeping a consistent base template those familiar with
MVC will recognise it.
To start were going to unpick a little bit of what we did in creating the homepage to sit the homepage
template under a master.
2. Now were going to move the Homepage template under the Master template. To do this select
the Settings > Homepage node and from the Properties tab >Master template drop down
select Master and then click Save. This will update the Razor code section to change Layout =
null; to Layout = Master.cshtml (you may have to click off the Homepage node and back on to
see this update a bug that will be fixed in a future release of Umbraco).
3. Now we need to move the parts of our HTML template that are common across all pages into the
Master. This is where as a developer you might need to use your brain as it will be slightly different
for different websites e.g. do all pages have a <div id=main> as so can we put this in the master
or does this belong to only certain pages? For this site well assume this is part of the child page. Cut
everything from the closing curly brace to line 37 <div id=main-container> - were going to move
the header and nav of the site to the master template. Cut this and click Save.
4. Now click on your Master template and paste this HTML markup after the closing curly brace and
remember to click Save.
5. At the end of this markup we need to tell Umbraco to insert the child templates content this is
done by adding the code @RenderBody() at the end (around line 37). Click Save.
6. Now well do the same with the footer content. Cut everything from the opening of the footer-
container div (approximately line 33) from the Settings > Templates > Homepage > template
tab, click Save and then paste this into the Master template under the @RenderBody field weve
just added. Remember to click Save.
7. Now weve done a lot of work and what we should see if we refresh our localhost page is nothing
has changed! If you have a compilation error youve perhaps mistyped @RenderBody(). If youre
missing any content (header or footer) check that what you have in the templates matches the
following:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<script src="js/libs/modernizr-2.0.6.min.js"></script>
</head>
<body>
<div id="header-container">
<header class="wrapper clearfix">
<h1 id="title">@Umbraco.Field("pageTitle")</h1>
<nav>
<ul>
<li><a href="#">nav ul li a</a></li>
<li><a href="#">nav ul li a</a></li>
@RenderBody()
<div id="footer-container">
<footer class="wrapper">
<h3>@Umbraco.Field("footerText")</h3>
</footer>
</div>
</body>
</html>
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "Master.cshtml";
}
<div id="main-container">
<div id="main" class="wrapper clearfix">
<article>
<header>
@Umbraco.Field("bodyText")
</header>
<section>
<h2>article section h2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum
iaculis libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis
nec. Curabitur posuere enim eget turpis feugiat tempor. Etiam ullamcorper lorem dapibus velit
suscipit ultrices. Proin in est sed erat facilisis pharetra.</p>
</section>
<section>
<h2>article section h2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum
iaculis libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis
nec. Curabitur posuere enim eget turpis feugiat tempor. Etiam ullamcorper lorem dapibus velit
suscipit ultrices. Proin in est sed erat facilisis pharetra.</p>
</section>
<footer>
<h3>article footer h3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum
iaculis libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis
nec. Curabitur posuere enim eget turpis feugiat tempor.</p>
</footer>
</article>
<aside>
<h3>aside</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum iaculis
libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis nec.
Curabitur posuere enim eget turpis feugiat tempor. Etiam ullamcorper lorem dapibus velit
suscipit ultrices.</p>
</aside>
If youre new to these concepts then I dont think what weve just done is going to make much sense
until we make our next page.
2. Go to Settings > Document Types (hover) > ... > + Create . Lets create one called Simple
Content Page. Leave the Master Document Type drop down to none... (the use of allows you to
inherit property types from parents, Id recommend you dont use it unless there is a definite need)
but well create a matching template so leave this checked.
3. Firstly lets select an Icon type the word Content into the filter and select the document icon. In
description type A simple content page, leave the Allowed Templates as it is (e.g. only Simple
Content page checked). Click Save.
4. Now click on the Settings > Templates (hover) > ... and then Reload Nodes. Click on your
Simple Content Paqe node and then the Properties tab. Change the Master template drop
down to select value Master this will mean that well get the header and footer from the master
just as we do in the Homepage template. Click Save then load the Template tab you should see
the portion of Razor code has updated to say Layout =Master.cshtml if it hasnt updated itself
click on a different node and then back again to reload it. Now add the following HTML to the
template and click Save.
<div id="main-container">
<div id="main" class="wrapper clearfix">
<section>
<h2>Header goes here</h2>
<p>Content goes here</p>
</section>
</div> <!-- #main -->
</div> <!-- #main-container -->
Figure 30 - Contact Us Template HTML
5. Now lets create a page using our new Document Type and Template go to Content >
Homepage (hover) > ... > Create. Oh but we cant! Well see an error like that below:
6. This is by design Umbraco limits the editors to only being able to create content in the places that
you, the developer, allows. This will stop a user from breaking a site design (or an entire site) when
they create a new homepage under the news container node later! Unfortunately this functionality
also confuses a lot of new Umbracians hence why we show you this error here.
Go to Settings > Homepage on the Structure tab youll see a list of checkboxes under a label
Allowed child nodetypes (be careful not to confuse this with the Info tabs Allowed templates
well cover that later). So we need to allow users to be able to create child nodes below our
Homepage of type Simple Content Page. Check the box and hit Save.
7. So there is the confusing bit first we create the Simple Content Page but then we have to allow
it to be created under the document type that will sit above it e.g. we create our new Document
Type but then have to update the Homepage settings to be able to use it. Well do this again later
when we create an Articles container and Article item well need to allow the Article items under the
container. Simple perhaps not but youll get used to it!
8. Now go back Content > Homepage (hover) > ... > Create now we have the Simple Content
Page! Select this and enter a name (red text at the top). You can see that we only have a
Properties tab here no data. This is different to the document type for the homepage as weve
not yet created any tabs nor data properties (e.g. no bodyText or pageTitle!). Click Save and
Publish.
9. Our Content tree will now reload and there will be a Contact Us page under the homepage. This
is the recommended structure for most sites your primary level 1 pages will sit under the
Homepage. Go look at this page if you look at the Properties tab you can see a Link To
document row click this. You might find an unstyled page again. This is because the template
designers have assumed that your site will be a flat structure e.g. all pages sitting at the same level
To:
JS <script src="js/libs/modernizr-2.0.6.min.js"></script>
<script src="/js/libs/modernizr-2.0.6.min.js"></script>
10. Save the template changes and reload your Contact Us page. Well now have a pretty empty
looking page.
11. Lets add two simple fields pageTitle (type = Textstring) and bodyText (type Rich Text Editor).
Follow the instructions in creating the Homepage document type if youre not sure how to do this.
Then wire these fields up by editing the Template, again follow the Homepage section if this isnt
yet second nature to you yet!
12. Now add some content under the Content > Homepage node > Contact Us node. Click Save
and Publish and you should have a slightly more interesting page when you reload it!
button again. here is where all of the options we ignored earlier come into play choose
footerText again from the Choose field dropdown but this time well check the Recursive
checkbox. This tells Umbraco that if the field doesnt exist at the node level for the page were
requesting (e.g. Contact US) it will look up the content tree (so in our example go to the Homepage
for this content) this means you could also create a footerText element at the Contact Us page if
you wanted the editor to override the site wide default but for fields like this its not normally used.
Click Insert and youll see a different bit of Razor is added : @Umbraco.Field("footerText", recursive:
true)
2. Save your changes and lets test our menu. Youll find that clicking on the Article link throws an
Umbraco error as weve not created this page yet. Lets do that now.
Articles Main
Tab = Intro
Articles Item
Tab = Contents
3. Now go to the Settings > Document Types >Articles Main node > Structure tab > Allowed
child nodetypes and check the Articles Item. This allows us to create items under the main
(which acts as a parent container). We also need to allow the Articles Main node to be created
under the Homepage node (do this in the Settings > Document Types > Homepage node >
Structure tab > Allowed child nodetypes dont check the Articles Item only the main
should be at this level).
Siempre Solutions Ltd www.siempresolutions.co.uk | Parent Pages with Infinite Children 26
4. Now go to Content > Homepage node (hover)> ... and create a node called Articles of type
Articles Main (if you dont have this option go back and check your allowed child nodes did you
forget to click Save)? Give the Articles node some content and a title and then create a couple of
article item content nodes under this node (Content > Homepage node > Articles node (hover)
> ...
5. Now you should have a content tree that looks like this below (obviously with your own content node
names that you added before). Lets go update our templates we just created (automatically when
we created the Document Types). First update them to use the Master as a parent Settings >
Templates > Articles Main node > Properties tab > Master template dropdown = Master
do the same for the Articles Item remembering to click Save.
6. Copy the template content from the Simple Content Page template and paste this into each
(clicking Save). Then replace the Page fields with the relevant e.g. articlesTitle and
articlesBodyText for the Articles Main and the articleTitle and articleContents for Article
Item.
7. If we now go and check our Articles Main page in the browser we should see our content. Now we
need to list the children under this so that we can see a list of our articles. Umbraco makes this easy
for us but we need to use a bit of Razor.
8. Click on the Developer menu from the left hand side menu and then hover over the Partial View
Macros Files node to get the more menu ... then click + Create. Name this listArticles and
select the List Child Pages Ordered By Date in the Choose a snippet field and click Create.
9. Now all we have to do is wire up the Articles main page to list our child articles. Edit the Articles Main
template Settings > Templates node > Master node > Articles Main node > Template tab.
Under the paragraph tags enter a carriage return and then click the Insert Macro button
then click Save.
10. Check what we have on our Articles page now - were really getting somewhere! Lets make it a bit
more real world Ill leave the understanding of this to Razor lessons / The Umbraco videos but it
will finish our site off nicely edit the Partial you just created Developer > Partial View Macro
Files > listArticles.cshtml and change the content to be:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
9 Conclusions
What we now have is a fully fledged working site! Hopefully this guide should have given you all of the
basics to see how to create your own site in Umbraco. For the majority of sites youll create they wont be
much more complicated than this. Weve not written any code nor have we needed to work much out of
the Umbraco UI.
This is not the limit of Umbraco youve barely scratched the surface in this guide.
For further reading / exercises Id recommend working through the video tutorials:
http://umbraco.com/help-and-support/video-tutorials.aspx
There is also a wiki (of which the intention is to use this guide to populate the Creating a basic site
with Umbraco section). http://our.umbraco.org/documentation
For help and guidance on anything this guide doesnt cover the forums are a great place to start:
http://our.umbraco.org/forum
This guide was produced by Steve Morgan of Siempre Solutions for more info contact him via
http://www.siempresolutions.co.uk
Happy Umbraco-ing!