好记性不如烂笔头。

Umbraco帮助文档 英文版

Umbraco帮助文档 英文版API

v6Razorcheatsheet.pdf (145.44 kb)

PDF文本内容

Umbraco v6.x Razor Cheatsheet
(DynmaicPublishedContent for MVC Templates, Partials, MacroPartials)
DynamicPublishedContent
@CurrentPage
Umbraco Properties
.Parent
.Id
.TemplateId
.SortOrder
.Name
.Visible
(requires umbracoNaviHide)
.Url
.UrlName
.DocumentTypeAlias
.WriterName
.CreatorName
.WriterID
.CreatorID
.Path
.CreateDate
.UpdateDate
.Level
Custom Properties Content & Media
.PropertyAlias
._propertyAlias (recursive)
.GetProperty(“propertyAlias”)
.GetPropertyValue(“propertyAlias”)
@Umbraco.Field(“propertyAlias”)
Use this for RTE properties to ensure
macros are rendered
Default Media Properties
.UmbracoFile
.UmbracoSize
.UmbracoWidth
.UmbrachHeight
Property Checking
.HasProperty(string propertyAlias)
.HasValue(string propertyAlias)
.IsNull(string propertyAlias)
@Umbraco helper
Loaders
.Content(int|string)
.ContentAtRoot()
.ContentAtXPath(xpathQuery)
.ContentAtXPathSingle(xpathQuery)
.Media(int|string)
.Search(term/ISearchCriteria[,SearchProvider])
Conditionals
.If(booleanStatement,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])
Collections
.Children
.ChildrenAsList
.[DocTypeName]s (Pluralized)
.Ancestors()
.Ancestors(int level)
.Ancestors(string nodeTypeAlias)
.AncestorsOrSelf()
.AncestorsOrSelf(string nodeTypeAlias)
.AncestorsOrSelf(int level)
.Descendants()
.Descendants(string nodeTypeAlias)
.Descendants(int level)
.DescendantsOrSelf()
.DescendantsOrSelf(int level)
.DescendantsOrSelf(string nodeTypeAlias)
Filtering & Ordering & Extensions
.Where(“Condition”)
.OrderBy(“propertyAlias [desc][,propertyAlias]”)
.Union(DynamicPublishedContentList)
.Intersect(DynamicPublishedContentList)
.Except(DynamicPublishedContentList)
.Distinct(“propertyAlias”)
.GroupBy(“propertyAlias”)
.Pluck(“propertyName”)
.Except()
.Take(int)
.Skip(int)
.Random()
.InGroupsOf(int)
Traversing
.Parent
.First()
.FirstOrDefault()
.Last()
.LastOrDefault()
.Single()
.SingleOrDefault()
.Sibling(int)
.Sibling(nodeTypeAlias)
.Up()
.Up(int) (0-based)
.Down()
.Down(int) (0-based)
.Next()
.Next(int) (0-based)
.Previous()
.Previous(int) (0-based)
Aggregate Functions
.Count()
.Min(“propertyAlias”)
.Max(“propertyAlias”)
.Average(“propertyAlias”)
.Sum(“propertyAlias”)
Permissions
.HasAccess()
.IsProtected()
Macro View Inheritance
@inherits Umbraco.Web.Macros.PartialViewMacroPage
Macro Parameters
@Model.MacroParameters[“paramAlias”]
Standard Umbraco Render Model (required to get access to Umbraco)
@inherits Umbraco.Core.Mvc.UmbracoTemplatePage
Dictionary
@Umbraco.Field(“#dictionaryKey”)
@Umbraco.GetDictionaryValue(“dicKey”)
IsHelpers
.IsFirst(valueIfTrue[,valueIfFalse])
.IsNotFirst(valueIfTrue[,valueIfFalse])
.IsLast(valueIfTrue[,valueIfFalse])
.IsNotLast(valueIfTrue[,valueIfFalse])
.IsPostion(int,valueIfTrue[,valueIfFalse])
.IsNotPosition(int,valueIfTrue[,valueIfFalse])
.IsModZero(int,valueIfTrue[,valueIfFalse])
.IsNotModZero(int,valueIfTrue[,valueIfFalse])
.IsEven(valueIfTrue[,valueIfFalse])
.IsOdd(valueIfTrue[,valueIfFalse])
.IsEqual(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
.IsNotEqual(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
.IsDescendant(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
.IsDescendantOrSelf(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
.IsAncestor(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
.IsAncestorOrSelf(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
littlewebempire.comUmbraco v6.x Razor Cheatsheet
(Strongly typed PublishedContent for MVC Templates, Partials, MacroPartials)
Property Checking
.HasProperty(string propertyAlias)
.HasValue(string propertyAlias)
.IsNull(string propertyAlias)
IPublishedContent
@Model.Content
Umbraco Properties
.Parent
.Id
.TemplateId
.GetTemplateAlias()
.SortOrder
.Name
.IsVisible() (requires umbracoNaviHide)
.Url
.UrlName
.DocumentTypeAlias
.WriterName
.CreatorName
.WriterID
.CreatorID
.Path
.CreateDate
.UpdateDate
.Level
Custom Properties Content & Media
.GetProperty(“propertyAlias”[,recursive(bool)])
.GetPropertyValue(“propertyAlias”)
.GetPropertyValue<type>(“propertyAlias”)
.GetPropertyRecursive(“propertyAlias”)
@Umbraco.Field(“propertyAlias”[,SEE OPTIONS])
Use this for RTE properties for proper rendering
OPTIONS:
altFieldAlias: “yourAltField”
altText: “your text”
insertBefore: “your text”
insertAfter: “your text”
recursive: boolean
convertLineBreaks: boolean
removeParagraphTags: boolean
casing: RenderFieldCaseType[.Lower/.Upper/.Title]
encoding: RenderFieldEncodingType[.Html/.Url]
formatAsDate: boolean
formatAsDateWithTime: boolean
formatAsDateWithTimeSeperator: “your seperator”
Collections
.Children
.ChildrenAsList
.Ancestors()
.Ancestors(int level)
.Ancestors(string nodeTypeAlias)
.AncestorsOrSelf()
.AncestorsOrSelf(string nodeTypeAlias)
.AncestorsOrSelf(int level)
.Descendants()
.Descendants(string nodeTypeAlias)
.Descendants(int level)
.DescendantsOrSelf()
.DescendantsOrSelf(int level)
.DescendantsOrSelf(string nodeTypeAlias)
Filtering & Ordering & Extensions
.Where(Lambda Expression*)
.OrderBy(Lambda Expression*)
.OrderByDescending(Lambda Expression*)
.Union(IEnumerable<IPublishedContent>[,IEQualityComparer])
.Intersect(IEnumerable<IPublishedContent>[,IEQualityComparer])
.Except(IEnumerable<IPublishedContent>[,IEQualityComparer])
.Distinct([IEqualityComparer])
.DistinctBy(Lambda Expression*)
.GroupBy(Lambda Expression*)
.Take(int)
.TakeWhile(Lambda Expression*)
.Skip(int)
.SkipWhile(Lambda Expression*)
.RandomOrder()
.InGroupsOf(int)
* Writing Lambda Expression Examples
var items = Model.Content.Where(x => x.IsVisible())
var items = Model.Content.OrderBy(x => x.UpdateDate)
Traversing
.Parent
.First()
.FirstOrDefault()
.Last()
.LastOrDefault()
.Single()
.SingleOrDefault()
.Sibling(int)
.Sibling(nodeTypeAlias)
.Up()
.Up(int) (0-based)
.Down()
.Down(int) (0-based)
.Next()
.Next(int) (0-based)
.Previous()
.Previous(int) (0-based)
Aggregate Functions
.Count()
.Min(Lambda Expression*)
.Max(Lambda Expression*)
.Average(Lambda Expression*)
.Sum(Lambda Expression*)
Standard Umbraco Render Model (required to get access to Umbraco)
@inherits Umbraco.Core.Mvc.UmbracoTemplatePage
Dictionary
@Umbraco.Field(“#dictionaryKey”)
@Umbraco.GetDictionaryValue(“dicKey”)
littlewebempire.com
@Umbraco helper
Loaders
.TypedContent(int|string)
.TypedContentAtRoot()
.TypedContentAtXPath(xpathQuery)
.TypedContentAtXPathSingle(xpathQuery)
.TypedMedia(int|string)
.TypedSearch(term[,searchProvider])
.TypedSearch(ISearchCriteria[,searchProvider])
Conditionals
.If(booleanStatement,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])
IsHelpers
.IsFirst(IfTrue[,IfFalse])
.IsNotFirst(IfTrue[,IfFalse])
.IsLast(IfTrue[,IfFalse])
.IsNotLast(IfTrue[,IfFalse])
.IsPostion(int,IfTrue[,IfFalse])
.IsNotPosition(int,IfTrue[,IfFalse])
.IsModZero(int,IfTrue[,IfFalse])
.IsNotModZero(int,IfTrue[,IfFalse])
.IsEven(IfTrue[,IfFalse])
.IsOdd(IfTrue[,IfFalse])
.IsEqual(IPublishedContent,IfTrue[,IfFalse])
.IsNotEqual(IPublishedContent,IfTrue[,IfFalse])
.IsDescendant(IPublishedContent,IfTrue[,IfFalse])
.IsDescendantOrSelf(IPublishedContent,IfTrue[,IfFalse])
.IsAncestor(IPublishedContent,IfTrue[,IfFalse])
.IsAncestorOrSelf(IPublishedContent,IfTrue[,IfFalse])
Permissions
.HasAccess()
.IsProtected()
Macro View Inheritance
@inherits Umbraco.Web.Macros.PartialViewMacroPage
Macro Parameters
@Model.MacroParameters[“paramAlias”]