Learn Creation Of Master Template In Umbraco CMS

Introduction

 
Welcome to the "Learn Umbraco CMS" article series. This article is Part 3 of the series. We will see how to create master Template in Umbraco CMS.
 
This article starts with the concept of Umbraco cms and its various components. The previous article provided an understanding of Creation Of Templates, Document Types And Content Page In Umbraco CMS the same that you can get from below,
Step 1
 
Lets add a new class file in controllers 
Learn Creation Of Master Template In Umbraco CMS
 
Learn Creation Of Master Template In Umbraco CMS

Step 2
 
Create a folder named sharedLayout and create header and footer view as shown below,
   
Learn Creation Of Master Template In Umbraco CMS

Learn Creation Of Master Template In Umbraco CMS
Step 3
 
Let's copy the header & footer part from the base template to the respective views, 
  1. <header id="header">    
  2.     <div class="inner">    
  3.         <a href="index.html" class="logo">introspect</a>    
  4.         <nav id="nav">    
  5.             <a href="index.html">Home</a>    
  6.             <a href="generic.html">Generic</a>    
  7.             <a href="elements.html">Elements</a>    
  8.         </nav>    
  9.     </div>    
  10. </header>    
  1. <section id="footer">    
  2.     <div class="inner">    
  3.         <header>    
  4.             <h2>Get in Touch</h2>    
  5.         </header>    
  6.         <form method="post" action="#">    
  7.             <div class="field half first">    
  8.                 <label for="name">Name</label>    
  9.                 <input type="text" name="name" id="name" />    
  10.             </div>    
  11.             <div class="field half">    
  12.                 <label for="email">Email</label>    
  13.                 <input type="text" name="email" id="email" />    
  14.             </div>    
  15.             <div class="field">    
  16.                 <label for="message">Message</label>    
  17.                 <textarea name="message" id="message" rows="6"></textarea>    
  18.             </div>    
  19.             <ul class="actions">    
  20.                 <li><input type="submit" value="Send Message" class="alt" /></li>    
  21.             </ul>    
  22.         </form>    
  23.         <div class="copyright">    
  24.             © Untitled Design: <a href="https://templated.co/">TEMPLATED</a>. Images <a href="https://unsplash.com/">Unsplash</a>    
  25.         </div>    
  26.     </div>    
  27. </section>    
Step 4
 
Now let's call the render action in the master template,
  1. @inherits Umbraco.Web.Mvc.UmbracoViewPage    
  2. @{    
  3.     Layout = null;    
  4. }    
  5.     
  6. @* the fun starts here *@    
  7.     
  8. <!DOCTYPE HTML>    
  9.     
  10. <html>    
  11. <head>    
  12.     <title>Introspect by TEMPLATED</title>    
  13.     <meta charset="utf-8" />    
  14.     <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />    
  15.     <link href="~/css/main.css" rel="stylesheet" />    
  16. </head>    
  17. <body>    
  18.     
  19.     <!-- Header -->    
  20.      
  21.     @{Html.RenderAction("RenderHeader""SiteSharedLayout"); }    
  22.     <a href="#menu" class="navPanelToggle"><span class="fa fa-bars"></span></a>    
  23.     @RenderBody()    
  24.     <!-- Banner -->    
  25.     <section id="banner">    
  26.         <div class="inner">    
  27.             <h1>    
  28.                 Introspect: <span>    
  29.                     A free + fully responsive<br />    
  30.                     site template by TEMPLATED    
  31.                 </span>    
  32.             </h1>    
  33.             <ul class="actions">    
  34.                 <li><a href="#" class="button alt">Get Started</a></li>    
  35.             </ul>    
  36.         </div>    
  37.     </section>    
  38.     
  39.     <!-- One -->    
  40.     <section id="one">    
  41.         <div class="inner">    
  42.             <header>    
  43.                 <h2>Magna Etiam Lorem</h2>    
  44.             </header>    
  45.             <p>Suspendisse mauris. Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Integer adipiscin sem. Nullam quis massa sit amet nibh viverra malesuada. Nunc sem lacus, accumsan quis, faucibus non, congue vel, arcu, erisque hendrerit tellus. Integer sagittis. Vivamus a mauris eget arcu gravida tristique. Nunc iaculis mi in ante.</p>    
  46.             <ul class="actions">    
  47.                 <li><a href="#" class="button alt">Learn More</a></li>    
  48.             </ul>    
  49.         </div>    
  50.     </section>    
  51.     
  52.     <!-- Two -->    
  53.     <section id="two">    
  54.         <div class="inner">    
  55.             <article>    
  56.                 <div class="content">    
  57.                     <header>    
  58.                         <h3>Pellentesque adipis</h3>    
  59.                     </header>    
  60.                     <div class="image fit">    
  61.                         <img src="images/pic01.jpg" alt="" />    
  62.                     </div>    
  63.                     <p>Cumsan mollis eros. Pellentesque a diam sit amet mi magna ullamcorper vehicula. Integer adipiscin sem. Nullam quis massa sit amet lorem ipsum feugiat tempus.</p>    
  64.                 </div>    
  65.             </article>    
  66.             <article class="alt">    
  67.                 <div class="content">    
  68.                     <header>    
  69.                         <h3>Morbi interdum mol</h3>    
  70.                     </header>    
  71.                     <div class="image fit">    
  72.                         <img src="images/pic02.jpg" alt="" />    
  73.                     </div>    
  74.                     <p>Cumsan mollis eros. Pellentesque a diam sit amet mi magna ullamcorper vehicula. Integer adipiscin sem. Nullam quis massa sit amet lorem ipsum feugiat tempus.</p>    
  75.                 </div>    
  76.             </article>    
  77.         </div>    
  78.     </section>    
  79.     
  80.     <!-- Three -->    
  81.     <section id="three">    
  82.         <div class="inner">    
  83.             <article>    
  84.                 <div class="content">    
  85.                     <span class="icon fa-laptop"></span>    
  86.                     <header>    
  87.                         <h3>Tempus Feugiat</h3>    
  88.                     </header>    
  89.                     <p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna lorem ullamcorper laoreet, lectus arcu.</p>    
  90.                     <ul class="actions">    
  91.                         <li><a href="#" class="button alt">Learn More</a></li>    
  92.                     </ul>    
  93.                 </div>    
  94.             </article>    
  95.             <article>    
  96.                 <div class="content">    
  97.                     <span class="icon fa-diamond"></span>    
  98.                     <header>    
  99.                         <h3>Aliquam Nulla</h3>    
  100.                     </header>    
  101.                     <p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed.</p>    
  102.                     <ul class="actions">    
  103.                         <li><a href="#" class="button alt">Learn More</a></li>    
  104.                     </ul>    
  105.                 </div>    
  106.             </article>    
  107.             <article>    
  108.                 <div class="content">    
  109.                     <span class="icon fa-laptop"></span>    
  110.                     <header>    
  111.                         <h3>Sed Magna</h3>    
  112.                     </header>    
  113.                     <p>Suspendisse mauris. Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula.</p>    
  114.                     <ul class="actions">    
  115.                         <li><a href="#" class="button alt">Learn More</a></li>    
  116.                     </ul>    
  117.                 </div>    
  118.             </article>    
  119.         </div>    
  120.     </section>    
  121.     
  122.     <!-- Footer -->    
  123.    @{Html.RenderAction("RenderFooter""SiteSharedLayout");}    
  124.     
  125.     <!-- Scripts -->s    
  126.     
  127.     
  128.     <script src="~/Scripts/jquery.min.js"></script>    
  129.     <script src="~/Scripts/skel.min.js"></script>    
  130.     <script src="~/Scripts/util.js"></script>    
  131.     <script src="~/Scripts/main.js"></script>    
  132. </body>    
  133. </html>    
Step 5
 
Now let's call the views in the controller which we have created in Step 1  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using Umbraco.Web.Mvc;  
  6. using System.Web.Mvc;  
  7. namespace Umbraco_CMS.Controllers  
  8. {  
  9.     public class SiteSharedLayoutController:SurfaceController  
  10.     {  
  11.         private const string Partial_Views_Path = "~/Views/Partials/SharedLayout/";  
  12.         public ActionResult RenderHeader()  
  13.         {  
  14.             return PartialView(string.Format("{0}Header.cshtml",Partial_Views_Path));  
  15.         }  
  16.   
  17.         public ActionResult RenderFooter()  
  18.         {  
  19.             return PartialView(string.Format("{0}Footer.cshtml",Partial_Views_Path));  
  20.         }  
  21.     }  
  22. }  

Summary


In this article, we have learned how to create Master Template in Umbraco CMS.In future articles, we will understand more about Master Template in Umbraco cms. I hope you have liked this.


Similar Articles