Posts

Umbraco 7 - Partial View - List FAQs - OR List Child Subpages of a particular Document Type

 Umbraco 7: List Child Subpages of a particular Document Type @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @if (CurrentPage.Children("FAQ").Any()) { <div class="toggle-main faq"> @foreach (var childPage in CurrentPage.Children("FAQ")) { <div class="toggle"> <div class="toggle-title"> <!--FAQ title--> <h3><!-- <i class="fa fa-question"></i> -->@childPage.faqquestion</h3> </div> <div class="toggle-content"> <!--FAQ Detail--> <div class="entry-content"> @childPage.faqanswer </div> </div> </div> } </div> }

Umbraco 7 - Partial View Bradcrumbs

 <h1>@CurrentPage.pageTitle</h1>   <nav class="bread-crumb">          <ul class="breadcrumb clearfix">       @foreach(var level in CurrentPage.Ancestors().Where("Visible")) {   <li><a href="@level.Url">@level.Name</a><span class="divider"></span></li>   }   <li>@CurrentPage.Name</li>             </ul>    </nav>

Umbraco 7 - C# Razor - Passing a parameter variable from a Template to a Partial View.

Image
Passing a parameter variable from a Template to a Partial View Example - Passing a Page Id to a Partial View. In the example below we are passing 3 page Ids (1090. 1091, 1092) to a partial view.  The Partial View will display the details for each of these nodes on a home page.  See final output below. 1) In your Template: @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1090}}) @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1091}}) @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1092}}) 2) The Partial View: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var thisPageId = 1090; var stringPage = @ViewData["pageId"]; thisPageId = Convert.ToInt32(stringPage); } <div class="col-md-4"> <arti...

Umbraco Razor A to Z Loop iterate Through Media Folders:

Image
Umbraco Razor A to Z Loop iterate Through Media Folders: @using Examine @using Examine.SearchCriteria @using UmbracoExamine @using System.Xml.XPath @helper DisplayDocImage(string thisExtension) { switch (thisExtension) { case "docx": case "doc": case "rtf": { @Html.Raw("Word Document"); break; } case "xls": case "xlsx": { @Html.Raw("Excel Spreadsheet Document"); break; } case "ppt": case "pps": case "pptx": case "ppsx": { @Html.Raw("Powerpoint Document"); ...

Umbraco Razor - Delete Pages by Category

The following script allows the User to delete a list of Event Pages by selecting a category: The Second Example is the same as the First except the Umbraco Data type is listed in a Dropdown. Demo Example 1: @inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.cms.businesslogic.web @{ @* 1. Get the Querystring that Contains the Catecory from Part 3 *@ var qdeleteCat = Request["deleteCat"]; /* Filter*/ if (Request["deleteCat"] != null) { qdeleteCat = Request["deleteCat"]; } else { qdeleteCat = ""; } @* ------------------------------------------------------------- *@ @* 2. Get the Querystring that Contains the Confrim from Part 3 *@ var qConfirm = Request["confirmDelete"]; /* Filter*/ if (Request[...

Umbraco 7 Partial View List Sub Pages from a Particular Node

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{   var startNode = Umbraco.Content(1105); try { foreach (var page in startNode.Children.Where("Visible")) { <li><a href="#">@page.Name</a></li> } } catch{} }

Umbraco Razor Simple Alternative Subnav

@inherits umbraco.MacroEngines.DynamicNodeContext @{  var startLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.StartLevel);  var finishLevel = String.IsNullOrEmpty(Parameter.Level) ? 8 : int.Parse(Parameter.FinishLevel);    var parent = Model.AncestorOrSelf(startLevel);  if (parent != null) { @traverse(parent,startLevel,finishLevel) ; } } @helper traverse(dynamic parent,int startLevel,int finishLevel) {  foreach (var node in parent.Children.Where("Visible")) {  var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " id=\"current\"" : ""; <li >  <a href="@node.Url">@node.Name</a>                                       ...

Umbraco Razor Alternative method for Breadcrumbs

@inherits umbraco.MacroEngines.DynamicNodeContext <a href="@Model.AncestorOrSelf(2).Url">@Model.AncestorOrSelf(2).Name</a> @try{ @Html.Raw(" | " + @Model.AncestorOrSelf(3).Name) } catch{} @try{ @Html.Raw(" | " + @Model.AncestorOrSelf(4).Name) } catch{} @try{ @Html.Raw(" | " + @Model.AncestorOrSelf(5).Name) } catch{}

Read in a CSV file using C# Razor in Umbraco and Display the details:

@{ try { var dataFile = Server.MapPath("~/App_Data/Contact-List.csv"); Array csvData = File.ReadAllLines(dataFile); int dataStartsRow = 5; int thisRow = 0; <h2>Reading File Starting at 5th Row, because that is where the data Starts</h2> foreach (string dataLine in csvData) { thisRow = thisRow  +1; int columnInSpreadsheet = 0; foreach (string dataItem in dataLine.Split(',')) { if (thisRow >= dataStartsRow) { @dataItem <br /> } } } } catch { <h2>Error:  Check to see if the file Contact-List.csv exists and is not open.</h2> } }

Umbraco Razor. Read Contents of A CSV File and Create nodes

The Script below reads the contents of a CSV Spreasheet in Razor, in Umbraco. It's pretty specific for something I was working on, but there are bits of code that can be reused: Loading a CSV file in Razor, Reading the Contents of a CSV file in Razor, Creating Nodes in Umbraco from a CSV file in Razor, Deleting Nodes using Razor. @inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.cms.businesslogic.web   <!-- This Script Reads from a CSV file in the Data App Folder -->   <!-- It then finds Dates in the File and Creates New Event Nodes with the Date as part of the name-->   <!-- There are 3 Types of Events, so it selects the type of event which is decided on by the column it is in-->   <!-- See the CSV for examples-->    <!-- The ETSR Mettings comes from a file "ETSRMeeting.csv" that should be stored in the App_Data folder.     The file is read in and used in the Events Calander. -->  ...