Posts

Umbraco 7 HTML Site Map Partial View

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var home = CurrentPage.Site(); } @if (home.Children.Any()) {     @* Get the first page in the children *@     var naviLevel = home.Children.First().Level;     var listChildPages = "false";     @* Add in level for a CSS hook *@     <ul style="margin-top:0px;paddin:0px;font-size:16px;">                 @* For each child page under the home node *@         <li><a href="/" title="@CurrentPage._siteTitle">Home</a></li>         @foreach (var childPage in home.Children.Where("Visible"))         {             if (childPage.Children.Any() && listChildPages =="true"  && childPage.id != 111...

Umbraco 7 Metadata, Keywords, Description and Title

@{            var SEOTitle = "";         var SEODescription = "";         var SEOKeywords = "";      }      @if(CurrentPage.seoTitle != null && CurrentPage.seoTitle != "")      {         SEOTitle = CurrentPage.seoTitle;      }      else      {         SEOTitle = @CurrentPage.Url.Replace("/"," | ") + @CurrentPage._siteTitle;         SEOTitle = SEOTitle.Substring(2, SEOTitle.Length-2);      }          @if(CurrentPage.seoDescription != null && CurrentPage.seoDesctiption != "")      {         SEODescription = CurrentPage.seoDescription;  ...

Umbraco 7 Hide a page from Navigation or Sub Navigation with umbracoNaviHide using Razor in a template or partial view

Image
How to Allow the user to Hide a Page from Navigation in Umbraco 7. By using a tick box: This example shows hide the Search Results page from the main navigation in umbraco 7. 1)  In your Document Type add a property called "umbracoNaviHide", it must be called "umbracoNaviHide" The property should be a tick box, so it should be a "True/False " 2) In your Navigation, add the highlighted code to your for each loop that writes out the navigation:   @foreach(var p in homePage.Children() .Where("visible") )                         {                             write out navigation 3) Now when the user ticks Hide from Nav in the backend, the page will not show in the navigation:

Umbraco 7 Previous and Next Buttons

This snippet shows Previous and Next  buttons on a page in Umbraco 7    <div class="nav-previous col-xs-6">                                     @if( @ CurrentPage.Previous() != null )                                     {                                     <h4><a href="@CurrentPage.Previous().Url" rel="prev">PREVIOUS GALLERY</a></h4>                             ...

Umbraco 7 Get the Text and Value from a Radio List

1) This snippet example shows you how to get the Text value of a radio list option in Umbraco 7 : @umbraco.library.GetPreValueAsString(CurrentPage.optionalLayouts) 2 ) This snippet example shows you how to get the Value of a radio list option in Umbraco 7 : @CurrentPage.optionalLayouts note:  "optionalLayouts" is the field name in the Umbraco back end in this example.

Umbraco 7 test for Odd and Even rows in a loop to display differenrt coloured rows or sections

The snippet example below shows one way of testing for Odd and Even in an umbraco foreach loop. The result is to list out odd and even background colours, suach as in bootstrap sections. @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{      var count = 0;        var colourClass = ""; }     @foreach(var childPage in Umbraco.Content(1067).Children().Where("NodeTypeAlias == \"newPageSection\""))     {                 if(count% 2 == 0)         {           colourClass="dark";         }         else         {            colourClass="light";         }         <div class="content-block conten...

Umbraco 7 Check to see if a filed HasVale and check to see if a Field IsNullOr Empty

The snippet below 1) Checks to see if the umbraco Field "sectionVideo" is Null or Empty. 2) Check to see if umbraco field "sectonImage" has a vale @if( String.IsNullOrEmpty(childPage.sectionVideo) && childPage.HasValue("sectionImage") )                         {                         <div class="col-lg-6">                             <img src="@childPage.GetCropUrl("sectionImage","rectangle")" />                         </div>                       ...

Umbraco Razor - One Way to Check to See if A Node or Page Still Exists and or is Published

This can be used, for example, in a Partial View to see if a node is publish and or exists to ensure that the page does not throw an error when trying to write out details from a page or it's sub nodes . @{ var thisPage = Umbraco.Content(1256); // Get the page } @if(thisPage.Path != null && thisPage.Path != "") {    // Write out content from that page  }

Umbraco Forms - Basics

Umbraco Forms Introduction: a) Stores the forms in the /App_Plugins/UmbracoForms/Data/forms/ folder b)  Stores the forms in JSON format c)  Gives each form a GUID, such as: ea-3e73-4b99-9d81-3055149e3c2e.json that can be used to reference the forms. In the main umbraco template add links to,  JQUERY,  Jquery Validation Jquery Unobtrusive Validation EX:    <!-- Javascripts -->     <script src="/js/jquery.min.js"></script>     <script src="/js/bootstrap.min.js"></script> <script src="/scripts/fanoe.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.js"></script> Umbraco Forms, list Forms from Directory: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Xml.XPath @using Sy...

Umbraco 7 Partial View - Main Navigation - C# - Razor - With Home Page

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var home = CurrentPage.Site(); } @if (home.Children.Any()) {     @* Get the first page in the children *@     var naviLevel = home.Children.First().Level;         @* Add in level for a CSS hook *@                       @* For each child page under the home node *@         foreach (var childPage in home.Children)         {   if(childPage.umbracoNaviHide != true) { if (childPage.Children.Any()) {                   <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "current-menu-item page_item" : null)"> @if(childPage.DocumentTypeAlias == "LandingPage") { <a href="@childPage.Url">@childPage.navigationName</a> @childPages(childPage.Children) } else { ...