Issuu on Google+

Umbraco 4.7.1 Razor + DynamicNode Cheat Sheet Document Version 1.2 Current Page

Collections

Traversing

Property Checking

@Model

.Children

.Parent

.HasProperty(string propertyAlias)

.First()

.HasValue(string propertyAlias)

Dynamic Node Properties

.[DocTypeName]s .Ancestors()

(Pluralized)

.Last()

.IsNull(string propertyAlias)

.Parent

.Ancestors(int level)

.Up()

.Id

.Ancestors(string nodeTypeAlias)

.Up(int) (note 0 = 1)

IsHelpers

.Template

.Ancestors(Func< DynamicNode, bool > func)

.Down()

.IsFirst([valueIfTrue][,valueIfFalse])

.SortOrder

.AncestorsOrSelf()

.Down(int) (note 0 = 1)

.IsNotFirst([valueIfTrue][,valueIfFalse])

.Name

.AncestorsOrSelf(string nodeTypeAlias)

.Next()

.IsLast([valueIfTrue][,valueIfFalse])

.Visible (requires umbracoNaviHide property)

.AncestorsOrSelf(int level)

.Next(int) (note 0 = 1)

.IsNotLast([valueIfTrue][,valueIfFalse])

.Url

.AncestorsOrSelf(Func< DynamicNode, bool > func)

.Previous()

.IsPosition(int,[valueIfTrue][,valueIfFalse])

.UrlName

.Descendants()

.Previous(int) (note 0 = 1)

.NodeTypeAlias

.Descendants(string nodeTypeAlias)

.IsNotPosition(int,[valueIfTrue][,valueIfFalse]) .IsModZero([valueIfTrue][,valueIfFalse])

.WriterName

.Descendants(int level)

Macro Parameters

.CreatorName

.Descendants(Func< INode, bool > func)

@Parameter.ParameterName

.WriterID

.DescendantsOrSelf()

.IsNotModZero([valueIfTrue][,valueIfFalse]) .IsEven([valueIfTrue][,valueIfFalse]) .IsOdd([valueIfTrue][,valueIfFalse])

.CreatorID

.DescendantsOrSelf(int level)

Media (use for media picker property)

.Path

.DescendantsOrSelf(string nodeTypeAlias)

.Media("propertyAlias","mediaPropertyAlias")

.IsDecendant(DynamicNode[,valueIfTrue][,valueIfFalse])

.CreateDate

.DescendantsOrSelf(Func< INode, bool > func)

.Media("propertyAlias")

.IsDecendantOrSelf(DynamicNode[,valueIfTrue][,valueIfFalse])

.UpdateDate

.XPath(string xPath)

.Version

.GetChildrenAsList

Types for Casting and Newing

.IsAncestorOrSelf(DynamicNode[,valueIfTrue][,valueIfFalse])

.Level

Filtering & Ordering & Extensions

DynamicMedia(int mediaId)

Permissions

.PropertiesAsList

.Where("Condition"[,valueIfTrue,valueIfFalse])

DynamicNodeList

.HasAccess()

.ChildrenAsList

.OrderBy("propertyAlias [desc][,propertyAlias]")

dynamic (allows .PropertyAlias notation)

.IsProtected()

.Position()

.GroupBy("propertyAlias")

.NiceUrl

.IsEqual(DynamicNode[,valueIfTrue][,valueIfFalse])

.IsAncestor(DynamicNode[,valueIfTrue][,valueIfFalse]) DynamicNode(int nodeId)

.Pluck("propertyName")

Razor Syntax

DynamicMedia Properties

.Take(int)

Code Block

Comments

.UmbracoFile

.Skip(int)

@{ ... }

@* Code comment *@

.UmbracoSize

.Count()

.UmbracoWidth .UmbrachHeight Custom Property Access (Content & Media) .PropertyAlias ._propertyAlias (recursive) .GetProperty("propertyAlias").Value Note: casing on property aliases are important. All hyphens must be removed for .Notation When accessing using .Notation you need to ensure you capitalize the first letter unless _recursive

Dictionary @Dictionary .DictionaryItemAlias

Functions @functions{ public bool isFooBar(string foo, string bar){ return foo == bar; } } @{ var foo = "black"; if(isFooBar(foo,"black")){ <p>Yup</p> } }

Conditionals @if(item.HasValue("bodyText"){ @item.BodyText }else if(item.IsNull("bodyText")){ <p>this item is null</p> }else{ <p>Some other text</p> } Looping @for(var i = 0; i < 10; i++){ This is record @i }

@switch(condition){ case: 1 <p>@item.BodyText</p> break; case: 2 <p>@item.Children.First().BodyText</p> break; default: break; }

@foreach(var item in Model.Children){ <p>@item.Name</p> } @Library Helper Loaders .NodeById(int|string) .MediaById(int|string) Condtionals .If(booleanProp,valueIfTrue[,valueIfFalse])

Manipulation .Coalesce(value,value[,value ...]) .Concatenate(value,value[,value ...) .Join(seperator,value,value[,value ...]) .Truncate(htmlString,int[[,bool addElipsis][,bool treatTagsAsContent]]) .StripHTML(htmlString[, tagsToString])

Visual Studio DynamicNode Intellisense Put the following at the head of the CSHTML file to get some Intellisense support for DynamicNode and DynamicNodeList @using umbraco.MacroEngines @inherits umbraco.MacroEngines.DynamicNodeContext


Test