Extension functions

AddJquery()

Adds a reference to the jQuery javascript file from the client/ui folder using "jQuery" as a key Recommended to use instead of RegisterJavaScriptFile for all nitros/packages that uses jQuery

ChangeContentType(MimeType)

Changes the mime type of the current page.

ContextKey(key)

Get any value from the current Items collection.

Returns: A string with the value of the Items element

CultureExists(cultureName)

Checks whether the Culture with the specified name exixts in the standard .net cultureInfo.

CurrentDate()

Get the current date

Returns: Current date i xml format (ToString("s"))

DateAdd(Date, AddType, add)

Add a value to a date

Returns: A date in xml format (ToString("s"))

DateAddWithDateTimeObject(Date, AddType, add)

Add a value to a date. Similar to the other overload, but uses a datetime object instead of a string

Returns: A date in xml format (ToString("s"))

DateDiff(firstDate, secondDate, diffType)

Return the difference between 2 dates, in either minutes, seconds or years.

Returns: A timespan as a integer

DateGreaterThan(firstDate, secondDate)

Compare two dates

Returns: True if the first date is greater than the second date

DateGreaterThanOrEqual(firstDate, secondDate)

Compare two dates

Returns: True if the first date is greater than or equal the second date

DateGreaterThanOrEqualToday(firstDate)

Check if a date is greater than or equal today

Returns: True if the date is greater that or equal today (ie. at least today or the day of tomorrow)

DateGreaterThanToday(firstDate)

Check if a date is greater than today

Returns: True if the date is greater that today (ie. at least the day of tomorrow)

FormatDateTime(Date, Format)

Formats a string to the specified formate.

Returns: A date in the new format as a string

GetCurrentDomains(NodeId)

Checks with the Assigned domains settings and retuns an array the the Domains matching the node

Returns: A Domain array with all the Domains that matches the nodeId

GetCurrentMember()

Get the current member as an xml node

Returns: Look in documentation for umbraco.library.GetMember(MemberId) for more information

GetDictionaryItem(Key)

Gets the dictionary item with the specified key.

Returns: A dictionary items value as a string.

GetDictionaryItems(Key)

Gets the dictionary item with the specified key and it's child dictionary items. The language version is based on the culture of the current Url.

Returns: A XpathNodeIterator in the format: [dictionaryItemValue]

GetHttpItem(key)

Get any value from the current Http Items collection

Returns: A string with the value of the Requested element

GetItem(nodeID, alias)

Returns a string with the data from the given element of a node. Both elements (data-fields) and properties can be used - ie: getItem(1, nodeName) will return a string with the name of the node with id=1 even though nodeName is a property and not an element (data-field).

Returns: Returns a string with the data from the given element of a node

GetItem(alias)

Returns a string with the data from the given element of the current node. Both elements (data-fields) and properties can be used - ie: getItem(nodeName) will return a string with the name of the current node/page even though nodeName is a property and not an element (data-field).

GetMedia(MediaId, Deep)

Get a media object as an xml object

Returns: An umbraco xml node of the media (same format as a document node)

GetMember(MemberId)

Get a member as an xml object

Returns: An umbraco xml node of the member (same format as a document node), but with two additional attributes on the "node" element: "email" and "loginName".

GetMemberName(MemberId)

Returns the Member Name from an umbraco member object

Returns: The Member name matching the MemberId, an empty string is member isn't found

GetNodeFromLevel(path, level)

Helper function to get a value from a comma separated string. Usefull to get a node identifier from a Page's path string

Returns: A string with the value of the index

GetPreValueAsString(Id)

Gets the umbraco data type prevalue with the specified Id as string.

Returns: Returns the prevalue as a string

GetPreValues(DataTypeId)

Gets the prevalues from a umbraco DataType with the specified data type id.

Returns: Returns the prevalues as a XPathNodeIterator in the format: [value]

GetPropertyTypeName(ContentTypeAlias, PropertyTypeAlias)

Returns that name of a generic property

Returns: A string with the name. If nothing matches the alias, an empty string is returned

GetRandom()

These random methods are from Eli Robillards blog - kudos for the work :-) http://weblogs.asp.net/erobillard/archive/2004/05/06/127374.aspx Get a Random object which is cached between requests. The advantage over creating the object locally is that the .Next call will always return a new value. If creating several times locally with a generated seed (like millisecond ticks), the same number can be returned.

Returns: A Random object which is cached between calls.

GetRandom()

GetRandom with no parameters.

Returns: A Random object which is cached between calls.

GetRelatedNodesAsXml(NodeId)

Gets the related nodes, of the node with the specified Id, as XML.

Returns: The related nodes as a XpathNodeIterator in the format: [standard umbraco node Xml]

GetUmbracoHelper()

Returns a new UmbracoHelper so that we can start moving the logic from some of these methods to it

GetWeekDay(Date)

Get the day of week from a date matching the current culture settings

Returns: A string with the DayOfWeek matching the current contexts culture settings

GetXmlAll()

Gets the entire umbraco xml cache.

Returns: Returns the entire umbraco Xml cache as a XPathNodeIterator

GetXmlDocument(Path, Relative)

Fetches a xml file from the specified path on the server. The path can be relative ("/path/to/file.xml") or absolute ("c:\folder\file.xml")

Returns: The xml file as a XpathNodeIterator

GetXmlDocumentByUrl(Url)

Fetches a xml file from the specified url. the Url can be a local url or even from a remote server.

Returns: The xml file as a XpathNodeIterator

GetXmlDocumentByUrl(Url, CacheInSeconds)

Gets the XML document by URL Cached.

GetXmlNodeById(id)

Gets the page with the specified id.

Returns: Returns the node with the specified id as xml in the form of a XPathNodeIterator

GetXmlNodeByXPath(xpathQuery)

Queries the umbraco Xml cache with the specified Xpath query

Returns: Returns nodes matching the xpath query as a XpathNodeIterator

GetXmlNodeCurrent()

Gets the current page.

Returns: An XpathNodeIterator containing the current page as Xml.

HasAccess(NodeId, Path)

Check if the current user has access to a document

Returns: True if the current user has access or if the current document isn't protected

HtmlEncode(Text)

HTML-encodes a string

Returns: A HTML-encoded string

IsLoggedOn()

Whether or not the current user is logged in (as a member)

Returns: True is the current user is logged in

IsProtected(DocumentId, Path)

Check if a document object is protected by the "Protect Pages" functionality in umbraco

Returns: True if the document object is protected

Item(nodeId, fieldName)

Creates an Umbraco item for the specified field of the specified node. This brings the umbraco:Item element functionality to XSLT documents, which enables Live Editing of XSLT generated content.

Returns: An Umbraco item.

Item(nodeId, fieldName, displayValue)

Creates an Umbraco item for the specified field of the specified node. This brings the umbraco:Item element functionality to XSLT documents, which enables Live Editing of XSLT generated content.

Returns: An Umbraco item.

JsonToXml(json)

This will convert a json structure to xml for use in xslt

LastIndexOf(Text, Value)

Returns the Last index of the specified value

Returns: Return the last index of a value as a integer

LongDate(Date, WithTime, TimeSplitter)

Converts a string to Long Date and returns it as a string

Returns: A Long Date as a string.

LongDate(Date)

Converts a string to a Long Date and returns it as a string

Returns: A Long Date as a string.

LongDateWithDayName(Date, DaySplitter, WithTime, TimeSplitter, GlobalAlias)

Converts a string to datetime in the longdate with day name format.

Returns: A datetime in the longdate formate with day name, as a string

NiceUrl(nodeID)

Returns a string with a friendly url from a node. IE.: Instead of having /482 (id) as an url, you can have /screenshots/developer/macros (spoken url)

Returns: String with a friendly url from a node

<a href="{umbraco.library:NiceUrl(@id)}">Link</a>

NiceUrlFullPath(nodeID)

This method will always add the root node to the path. You should always use NiceUrl, as that is the only one who checks for toplevel node settings in the web.config

Returns: String with a friendly url from a node

NiceUrlWithDomain(nodeID)

This method will always add the domain to the path if the hostnames are set up correctly.

Returns: String with a friendly url with full domain from a node

NiceUrlWithDomain(nodeID, ignoreUmbracoHostNames)

This method will always add the domain to the path.

Returns: String with a friendly url with full domain from a node

PageElement(key)

Returns any element from the currentpage including generic properties

Returns: A string with the element value

PageId()

Returns the identifier of the current page

Returns: The identifier of the current page

PageName()

Returns the title of the current page

Returns: The title of the current page

PublishSingleNode(DocumentId)

Publishes the single node, this method is obsolete

PythonExecute(expression)

Executes the given python expression and returns the standardoutput. The Globals known from python macros are not accessible in this context. Neighter macro or page nor the globals known from python macros are accessible in this context. Only stuff we initialized in site.py can be used.

Returns: Returns the StandardOutput

PythonExecuteFile(file)

Executes the given python script and returns the standardoutput. The Globals known from python macros are not accessible in this context. Neither macro or page nor the globals known from python macros are accessible in this context. Only stuff we initialized in site.py can be used.

Returns: Returns the StandardOutput

QueryForNode(id)

Returns the Xpath query for a node with the specified id

Returns: The Xpath query for the node with the specified id as a string

RePublishNodes(nodeID)

Re-publishes all nodes under a given node

RePublishNodesDotNet(nodeID)

Re-publishes all nodes under a given node

RePublishNodesDotNet(nodeID, SaveToDisk)

Refreshes the runtime xml index. Note: This *doesn't* mark any non-published document objects as published

RefreshContent()

Refreshes the xml cache for all nodes

RegisterClientScriptBlock(key, script, addScriptTags)

Registers the client script block.

RegisterJavaScriptFile(key, url)

Registers the client script include.

RegisterStyleSheetFile(key, url)

Registers the client script include.

RemoveFirstParagraphTag(text)

Removes the starting and ending paragraph tags in a string.

Returns: Returns the string without starting and endning paragraph tags

RenderMacroContent(Text, PageId)

Renders the content of a macro. Uses the normal template umbraco macro markup as input. This only works properly with xslt macros. Python and .ascx based macros will not render properly, as viewstate is not included.

Returns: The rendered macro as a string

RenderTemplate(PageId, TemplateId)

Renders a template.

Returns: The rendered template as a string

RenderTemplate(PageId)

Renders the default template for a specific page.

Returns: The rendered template as a string.

Replace(text, oldValue, newValue)

Replaces a specified value with a new one.

ReplaceLineBreaks(text)

Replaces text line breaks with html line breaks

Returns: The text with text line breaks replaced with html linebreaks ()

Request(key)

Get any value from the current Request collection. Please note that there also specialized methods for Querystring, Form, Servervariables and Cookie collections

Returns: A string with the value of the Requested element

RequestCookies(key)

Get any value from the users cookie collection

Returns: A string with the value of the cookie

RequestForm(key)

Get any value from the current Form collection

Returns: A string with the value of the form element

RequestQueryString(key)

Get any value from the current Querystring collection

Returns: A string with the value of the querystring element

RequestServerVariables(key)

Get any element from the server variables collection

Returns: A string with the value of the requested element

SendMail(FromMail, ToMail, Subject, Body, IsHtml)

Sends an e-mail using the System.Net.Mail.MailMessage object

Session(key)

Get any element from current user session

Returns: A string with the value of the requested element

SessionId()

Returns the current ASP.NET session identifier

Returns: The current ASP.NET session identifier

ShortDate(Date)

Converts a string to a Short Date and returns it as a string

Returns: A Short Date as a string.

ShortDate(Date, WithTime, TimeSplitter)

Converts a datetime string to the ShortDate format.

ShortDateWithGlobal(Date, GlobalAlias)

Converts a string to a Short Date, with a specific culture, and returns it as a string

Returns: A short date with a specific culture, as a string

ShortDateWithTimeAndGlobal(Date, GlobalAlias)

Converts a string to a Short Date with time, with a specific culture, and returns it as a string

Returns: A short date withi time, with a specific culture, as a string

ShortTime(Date)

Converts a datetime string to the ShortTime format.

Split(StringToSplit, Separator)

Split a string into xml elements

Returns: An XPathNodeIterator containing the substrings in the format of

StripHtml(text)

Strips all html from a string.

Returns: Returns the string without any html tags.

Tidy(StringToTidy, LiveEditing)

Cleans the spified string with tidy

TruncateString(Text, MaxLength, AddString)

Truncates a string if it's too long

Returns: A truncated string if text if longer than MaxLength appended with the addString parameters. If text is shorter then MaxLength then the full - non-truncated - string is returned

UnPublishSingleNode(DocumentId)

Unpublish a node, by removing it from the runtime xml index. Note, prior to this the Document should be marked unpublished by setting the publish property on the document object to false

UpdateDocumentCache(documentId)

Publishes a Document by adding it to the runtime xml index. Note, prior to this the Document should be marked published by calling Publish(User u) on the document object.

UrlEncode(Text)

URL-encodes a string

Returns: A URL-encoded string

md5(text)

Returns an MD5 hash of the string specified

Returns: Md5 has of the string

setCookie(key, value)

Add a cookie variable to the current user

setSession(key, value)

Add a session variable to the current user

Fork me on GitHub