Posts

Showing posts from January, 2014

Umbraco Razor Crops - One way of checking if the Crop exists

This bit of code (highlighted yellow) writes out the Count of a cropped image as a comment, if it fails a default image is written out. @inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.cms.businesslogic.template; @using System.Xml.XPath @{ int foundMatch = 0; string outPutText = ""; foreach (var page in Model.Children) { var thisImage = page.homePageImage; var mediaItem = Model.MediaById(@thisImage);   if (@mediaItem.CroppedImages.Count() > 0)   { <hr /> @Html.Raw("<article class=\"\">"); <div> <div class="one_half first"> <a href="@page.Url" title="@page.navigationName"> @try { @Html.Raw("<!--" + @mediaItem.CroppedImages.Find("@name", "mediumImage").Count

Umbraco - Racor - C# - Colllections - Add Node ids

If you are working with folders in razor, it may be best to add them as a collection to iterate through instead of having to look work with the folder structure continually: //Lets Build a collection of the all the documents to look at: var docuList = new List<string>(); dynamic documentFolders = Library.NodeById(rootMediaFolder);     foreach (var folders in documentFolders.Children) {   dynamic subFolders = Library.NodeById(@folders.Id);   foreach (var thisDocuments in subFolders.Children) { docuList.Add(@thisDocuments.id); } } foreach (var document in docuList) { @document }

Implementing uComponents Multiple URL picker in Umbraco

Set up Ucomponents in Umbrao: 1) Download the uComponents package 2) Install the Package in Umbraco Set up a Datatype to reference: 1) Create a New Data type, for Example: "Multiple Media Picker" 2) Select the Type as "Ucomponents Multi Url Picker" 3) Choose "Media" as allowed types 4) Data format "HTML" Set up your Document type: 1) Create a new field in your document type, for example "pickDocuments" 2) Set the field to be a Type: "Multile Media Picker" Create a New Macro: See Previous post for an Example for a break down of this code: @inherits umbraco.MacroEngines.DynamicNodeContext @using uComponents.Core @using uComponents.DataTypes.UrlPicker.Dto; @{                   if (Model.HasValue("pickDocuments2")) { // 1) Get the documents List         var urlPicker = Model.GetPropertyValue<UrlPickerState>("pickDocuments2"); //2) Get Type and display full strin

Umbraco C# Razor - Parsing XML example using uComponents URL picker to a list of Documents from the Media section

Image
The code below shows you how to get a chosen list of documents using the uComponents Multi-Url picker The Code that is comment out highlights the steps to get to the end result. The Code shows how to parse raw XML in Razor. Here is what the code does: Step 1) "Get the Document List:" var urlPicker = Model.GetPropertyValue<UrlPickerState>("pickDocuments"); "pickDocuments" is the field in my Document Type it is a uComponents Multi Midia Picker Step 2) Get Type and display full string: This code is comment out - if you uncoment it, it will show you the raw XML that needs to be parsed, for example: @urlPicker  displays the xml: <multi-url-picker><url-picker mode="Media"><new-window>False</new-window><node-id>1721</node-id><url>/media/53699/learning-log-v4-macroless-.xls</url><link-title /></url-picker><url-picker mode="Media"><new-window>Fal

Umbraco Razor 2nd Level Navigation - Check to see whether the Current Page is a Child of the Page being written out

Umbraco Razor 2nd Level Navigation - Check to see whether the Current Page is a Child of the Page being written out, if so syle it: @inherits umbraco.MacroEngines.DynamicNodeContext @{   var startLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.StartLevel);   var finishLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.FinishLevel);     var parent = @Model.AncestorOrSelf(startLevel);   if (parent != null) { @traverse(parent,startLevel,finishLevel) ; } }                                                                   @helper traverse(dynamic parent,int startLevel,int finishLevel) { int test = parent.Children.Count(); if (test > 0) { @Html.Raw("<div class=\"wrapper row9\">"); @Html.Raw("<div id=\"container1\">");   @Html.Raw("<div id=\"navcontainer\">"); @Html.Raw("<ul id=\"navlist\">");

Top Level Navigation - Umbraco Razor - Drop Down Navigation - With Home Page Active Checl

Image
@using umbraco.MacroEngines <ul class="clear"> @if (@Model.AncestorOrSelf(1).Id == @Model.Id) {     <li class="active"><a href="/" >Home</a> </li> } else { <li><a href="/">Home</a> </li> }     @foreach (var page in @Model.AncestorOrSelf(1).Children.Where("visible"))     {         string style = ""; if (Model.Id == page.Id) { @Html.Raw("<li class=\"active\">"); } else { @Html.Raw("<li>"); } if (page.Childen != null && page.Children.Count() > 0 && page.NodeId != "1093" && page.Id != 1688) { @Html.Raw("<a href=\"" + @page.Url + "\"  class=\'drop\'>" + @page.navigationName  +  "</a>"); } else { <a href="@page.Url" @Html.Ra

Umbraco Razor C# to List Documents from a Particular Folder, List the File Sizes to 2 Decimail Pace, and Date of the Umbraco Files

Image
The Script Below: 1) Lists the Files in  a folder Chosen from the Media Pickers 2) Converts / Parses the umbracoBytes to KBS and MB 3) Rounds the Umbraco File Size to 2 Decimal Paces 4) Formats the Razor Umbraco Date for Output 5) Writes out the Size of the Files in KBs 6) Writes out the formated Fate 3) Writes out a description of the document.   foreach (var folder in imageFolder.Children)   {   try{ double KBsize = 0; double MBsize = 0; double FileSize = Int32.Parse(@folder.umbracoBytes); KBsize = FileSize / 1024; MBsize = FileSize / 1048576; // Round KB Size to 2 Decimal Points KBsize = Math.Round(KBsize, 2); // Format Date string outDate = @library.FormatDateTime(@folder.createDate, "dd/MM/yyyy");   <p>&bull; <a href="@folder.Url">@folder.Name (@folder.umbracoExtension) | File Size:  @KBsize KB | Date Created:  @outDate</a> <