Methods in transformations

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following expressions can be used in transformation code:

 

Community and membership

 

GetAge(object dateOfBirth, string unknownAge)

<%# GetAge(Eval("UserDateOfBirth"),"Unknown age") %>

Returns age according to the date of birth given in the first parameter. If the date of birth is not available, the method returns the string specified in the second parameter.

 

GetGender(object genderObj)

<%# GetGender(Eval("UserGender")) %>

Returns gender of the currently transformed user based on value from the gender field specified in the parameter. If no gender is found, N/A is returned.

 

GetGroupAvatarImage(int maxSideSize, object alt)

<%# GetGroupAvatarImage(200, "Alternate text") %>

Returns image tag of the avatar contained in the AvatarGuid field of the currently transformed group, with maximum side size specified in the first parameter. The second parameter specifies value of the alt attribute of the image tag.

 

GetGroupAvatarImage(object avatarID, int maxSideSize, object alt)

<%# GetGroupAvatarImage(Eval("GroupAvatarID"), 200, "Alternate text") %>

Returns image tag of the avatar with the identifier specified in the first parameter, with maximum side size specified in the second parameter. The third parameter specifies value of the alt attribute of the image tag.

 

GetGroupAvatarImage(object avatarID, int maxSideSize, int width, int height, object alt)

<%# GetGroupAvatarImage(Eval("GroupAvatarID"), 200, 150, 150, "Alternate text") %>

Returns image tag of the avatar with the identifier specified in the first parameter, with maximum side size specified in the second parameter and maximum width and height specified in the third and fourth parameter. The fifth parameter specifies value of the alt attribute of the image tag.

 

GetGroupProfileUrl(object groupNameObj)

<%# GetGroupProfileUrl(Eval("GroupName") %>

Returns URL of the given group's profile.

 

GetMemberProfileUrl(object memberNameObj)

<%# GetMemberProfileUrl(Eval("UserName")) %>

Returns URL of the given user's profile.

 

GetUserAvatarImage(int maxSideSize, string alt)

<%# GetUserAvatarImage(200, "Alternate text") %>

Returns image tag of the avatar contained in the AvatarGuid field of the currently transformed user, with maximum side size specified in the  first parameter. The second parameter specifies value of the alt attribute of the image tag.

 

GetUserAvatarImage(object avatarID, object userID, int maxSideSize, object alt)

<%# GetUserAvatarImage(Eval("UserAvatarID"), Eval("UserID"), 200, "Alternate text") %>

Returns image tag of the avatar with identifier specified in the first parameter, of the user whose identifier is specified in the second parameter, with maximum side size specified in the third parameter. The last parameter specifies value of the alt attribute of the image tag.

 

GetUserAvatarImage(object avatarID, object userID, int maxSideSize, int width, int height, object alt)

<%# GetUserAvatarImage(Eval("UserAvatarID"), Eval("UserID"), 200, 150, 150, "Alternate text") %>

Returns image tag of the avatar with identifier specified in the first parameter, of the user whose identifier is specified in the second parameter, with maximum side size specified in the third parameter and maximum width and height specified in the fourth and fifth parameter. The last parameter specifies value of the alt attribute of the image tag.

 

GetUserProfileURL(object userNameObj )

<%# GetUserProfileURL(Eval("UserName")) %>

Returns URL of the user profile of the user whose user name is specified in the only parameter of the method.

 

Data

 

DataItem{get;}

<%# ((DataRowView)Container.DataItem)["UserName"] %>

Gets the DataItem object of the current binding context.

 

DataItemIndex{get;}

<%# DataItemIndex %>

Gets the data item index for current transformation container. You have to use Container.DataItemIndex for an index in current binding context.

 

DataRowView{get;}

<%# Container.DataRowView["UserName"] %>

Gets the DataRowView of the current record data.

 

DisplayIndex{get;}

<%# DisplayIndex %>

Gets the current position of the data item as displayed in a control.

 

DocumentCustomData{get;}

<%# DocumentCustomData["myproperty2"] %>

Gets the document custom data value (culture specific). DocumentCustomData is a database column which may contain a custom XML. Using the ["nodename"] notation, you can retrieve data stored in the specified node of the XML.

 

EditableItems{get;}

<%# EditableItems["mainText"] %>

Gets the editable region value.

 

Eval(string columnName)

<%# Eval("NewsTitle") %>

Returns the value of the given field.

 

Eval<ReturnType>(string columnName)

<%# GetBlogCommentsCount(Eval("DocumentID"), Eval<string>("NodeAliasPath")) %>

The Eval method described above returns a value of the object data type by default. This method provides the option to return a value of the data type specified within the angle brackets.

 

Eval(string columnName, bool encode)

<%# Eval("NewsTitle", true) %>

Returns the value of the given field. If the second parameter is true, the value will be HTML encoded.

 

GetEditableValue(string controlId)

<%# GetEditableValue("mainText") %>

Gets text entered in the specified editable region. The functionality is analogical to EditableItems{get;}.

 

NodeCustomData{get;}

<%# NodeCustomData["myproperty1"] %>

Similar to DocumentCustomData{get;}, with the difference that this method gets the node custom data value from the NodeCustomData column of the record in the CMS_Tree database table, which is common for all cultural versions of the transformed object.

 

Date & time

 

FormatDateTime(object dateTime, string format)

<%# FormatDateTime(DateTime.Now, "MM/dd/yyyy HH:mm") %>

Formats the date-time specified in the first parameter according to the format specified in the second parameter.

 

GetCustomDateTime(object dateTime, string timeZoneName)

<%# GetCustomDateTime(DateTime.Now, "GreenwichMeanTime") %>

Returns the date-time specified in the first parameter converted to the time zone specified in the second parameter.

 

GetDate(string dateTimeField)

<%# GetDate("NewsReleaseDate") %>

Returns date from the specified date-time field.

 

GetDateTime(string dateTimeField)

<%# GetDateTime("NewsReleaseDate") %>

Returns the date-time value from the specified field.

 

GetDateTime(string dateTimeField, string formattingString)

<%# GetDateTime("NewsReleaseDate", "MM/dd/yyyy HH:mm") %>

Returns formatted date-time value from the specified date-time field in the given format.

 

GetSiteDateTime(object dateTime)

<%# GetSiteDateTime(Eval("NewsReleaseDate")) %>

Returns the provided date-time converted to the current site's time zone.

 

GetUserDateTime(object dateTime)

<%# GetUserDateTime(Eval("NewsReleaseDate")) %>

Returns the provided date-time converted to the current user's time zone.

 

Document links and URLs

 

GetAbsoluteUrl(string relativeUrl, int siteId)

<%# GetAbsoluteUrl("~/Home.aspx", Eval<int>("NodeSiteID")) %>

Converts the provided relative URL to an absolute URL with the domain name of site specified by the identifier provided in the second parameter.

 

GetAbsoluteUrl(string relativeUrl, object siteNameObj)

<%# GetAbsoluteUrl("~/Home.aspx", Eval("SiteName")) %>

Converts the provided relative URL to an absolute URL with the domain name of the site whose name is provided in the second parameter.

 

GetAttachmentIconUrl(object attachmentExtension, string iconSet)

<%# GetAttachmentIconUrl(Eval("AttachmentExtension"), "List") %>

Returns URL of the file type icon according to the specified extension. The second parameter is the name of the icon-set sub-folder where the icons are stored.

 

GetAttachmentUrl(string attachmentFileName, string nodeAliasPath)

<%# GetAttachmentUrl(Eval<string>("AttachmentName"), Eval<string>("NodeAliasPath")) %>

Returns URL of the attachment with a name specified in the first parameter of the document with nodeAliasPath specified in the second parameter. This method returns the same URL as the GetFileUrl method, but needn't load the whole document, which results in better performance.

 

GetBlogCommentUrl(object documentIdObj)

<%# GetBlogCommentUrl(Eval("DocumentID")) %>

Returns URL of the blog post where the specified blog comment was added, based on the provided document identifier.

 

GetDocumentLink()

<%# GetDocumentLink() %>

Returns complete HTML code of a link pointing to the currently rendered document. The document name is encoded by default.

 

GetDocumentLink(bool encodeName)

<%# GetDocumentLink(false) %>

Returns complete HTML code of a link pointing to the currently rendered document. If the second parameter is set to false, the method does not encode the document name.

 

GetDocumentUrl()

<%# GetDocumentUrl() %>

Returns URL of the currently rendered document.

 

GetDocumentUrl(object nodeGuidColumn, object nodeAlias)

<%# GetDocumentUrl(Eval("NodeGUID"), Eval("NodeAlias")) %>

Returns permanent URL (with NodeGUID in querystring) of the specified document. The document is specified by its node GUID in the first parameter and its node alias in the second parameter.

 

GetFileIconUrl(object attachmentGuidColumn)

<%# GetFileIconUrl("FileAttachment") %>

Returns URL of the file type icon according to the extension of the file stored in the specified column.

 

GetFileIconUrl(object attachmentGuidColumn, string iconSet)

<%# GetFileIconUrl("FileAttachment", "List") %>

Returns URL of the file type icon according to the extension of the file stored in the specified column. The second parameter is the name of the icon-set sub-folder where the icons are stored.

 

GetFileUrl(object attachmentGuidColumn)

<%# GetFileUrl("ProductPhoto") %>

Returns URL of the file specified by the attachment GUID column of the given name.

 

GetFileUrl(object attachmentFileName, object attachmentDocumentId)

<%# GetFileUrl(Eval("AttachmentFileName"), Eval("AttachmentDocumentID")) %>

Returns URL of the attachment with the name specified in the first parameter of the document with identifier specified in the second parameter.

 

GetForumPostUrl(object postIdPath, object forumId)

<%# GetForumPostUrl(Eval("PostIDPath"), Eval("ForumID")) %>

Returns URL of the forum post specified by the path in the first parameter, from the forum specified by the identifier in the second parameter.

 

GetMediaFileUrl(object fileGUID, object fileName)

<%# GetMediaFileUrl(Eval("FileGUID") ,Eval("FileName")) %>

Returns URL of the specified media file. The media file is specified by the file GUID in the first parameter and its name in the second parameter.

 

GetMessageBoardUrl(object documentIdObj)

<%# GetMessageBoardUrl(Eval("BoardDocumentID")) %>

Returns URL of the document where the specified message board is placed, based on the the document identifier provided in the parameter.

 

GetProductUrl(object skuGUID, object skuName, object siteName)

<%# GetProductUrlForFeed(Eval("SKUGUID"), Eval("SKUName"), Eval("SiteName") %>

Returns URL of the product specified by the GUID in the first parameter, SKU name in the second parameter and site name in the last parameter.

 

GetUserAvatarImageUrl(object avatarID, object userID, int maxSideSize, int width, int height)

<%# GetUserAvatarImageUrl(Eval("UserAvatarID"), Eval("UserID"), 200, 150, 150) %>

Returns avatar image URL based on the avatar identifier provided in the first parameter. If the avatar is not defined, returns a gender dependent avatar based on the identifier of the user provided in the second parameter, or a default user avatar if it is defined.

 

GetUrl(object aliasPath, object urlPath)

<%# GetUrl(Eval("NodeAliasPath"), Eval("DocumentUrlPath")) %>

Returns URL of the document specified by its alias path in the first parameter or its URL path specified in the second one.

 

GetUrl(object aliasPath, object urlPath, object siteName)

<%# GetUrl(Eval("NodeAliasPath"), Eval("DocumentUrlPath"), Eval("SiteName")) %>

Returns URL of the specified document similarly as the method above, but from a site specified in the third parameter.

 

Images

 

GetImage(object attachmentGuidColumn)

<%# GetImage("NewsTeaser") %>

Returns complete HTML code of the image whose GUID is stored in the column of the given name.

 

GetImage(object attachmentGuidColumn, int maxSideSize)

<%# GetImage("NewsTeaser", 200) %>

Returns complete HTML code of the image whose GUID is stored in the column of the given name. The second parameter is the maximal side size of the returned img tag in pixels.

 

GetImage(object attachmentGuidColumn, int width, int height)

<%# GetImage("NewsTeaser", 200, 100) %>

Returns complete HTML code of the image whose GUID is stored in the column of the name specified in the first parameter, with maximal width and height specified in the second and third parameter.

 

GetImage(object attachmentGuidColumn, object maxSideSize, object width, object height)

<%# GetImage("NewsTeaser", 200, 200, 100) %>

Returns complete HTML code of the image whose GUID is stored in the column of the name specified in the first parameter, with maximal width and height specified in the second and third parameter and maximal side size specified in the fourth parameter.

 

GetImage(object attachmentGuidColumn, object maxSideSize, object width, object height, object alt)

<%# GetImage("NewsTeaser", 200, 200, 100, "image") %>

Returns complete HTML code of the image specified the same way as in the method above, while the fifth parameter defines value of the returned img tag's alt attribute.

 

GetImageByUrl(object imageUrl )

<%# GetImageByUrl("~/Images/Image1.aspx") %>

Returns complete HTML code of the image specified by its URL.

 

GetImageByUrl(object imageUrl, int width, int height)

<%# GetImageByUrl("~/Images/Image1.aspx", 100, 200) %>

Returns complete HTML code of the image specified by its URL, with maximal width and height (in pixels) specified in the second and third parameter.

 

GetImageByUrl(object imageUrl, int maxSideSize)

<%# GetImageByUrl("~/Images/Image1.aspx", 200) %>

Returns complete HTML code of the image specified by its URL, with maximal side size (in pixels) specified in the second parameter.

 

GetImageByUrl(object imageUrl, object maxSideSize, object width, object height, object alt)

<%# GetImageByUrl("~/Images/Image1.aspx", 200, 100, 200, "image") %>

Returns complete HTML code of the image specified by its URL, with maximal side size specified in the second parameter and maximal width and height specified in the third and fourth parameter. The fifth parameter defines the value of the alt atribute of the returned img tag.

 

IfImage(object attachmentGuidColumn, object isImage, object notImage)

<%# IfImage("NewsTeaser", "It is an image", "It isn't an image") %>

If the column specified in the first parameter contains a GUID of an image, the method returns the value of the first parameter. If it is not an image, it returns the value of the second parameter.

 

Microsoft SharePoint

 

SplitSharePointField(string value, int index)

<%# SplitSharePointField((string)Eval("ows_FileRef"),1)) %>

Helper function for splitting combined fields returned by SharePoint. E.g. ows_LastModified="1;#2009-03-17T10:32:17Z". The first parameter is the original combined field, the second is the index of the returned part.

 

GetSharePointFileUrl(string value, int index)

<%# GetSharePointFileUrl("tester4", SharePointFunctions.SplitSharePointField((string)Eval("ows_FileRef"),1)) %>

Returns URL link to get the specified document or picture from the SharePoint server. The first parameter is the SharePoint server URL, the second one is the path and name of the document to download.

 

Text

 

EnsureMaximumLineLength(object textObj, int maxLength)

<%# EnsureMaximumLineLength("SomeVeryLongStringWithoutAnyBlankSpaces", 20) %>

Ensures a line break of a long uninterrupted text specified in the first parameter (such as a URL) after the number of characters specified in the second parameter.

 

HTMLEncode(string text)

<%# HTMLEncode("Sample text <br />") %>

Encodes HTML tags in the given text.

 

LimitLength(object textObj, int maxLength, string padString)

<%# LimitLength("Some example long text", 10 , "...") %>

Limits text specified in the first parameter to the length specified in the second parameter. The last parameter is the trimming postfix, i.e. the string appended to the end of the shortened string. The trimming postfix is included in the maximal length, i.e. if the "..." postfix is used with maximal length of 100 characters, the returned string will have the first 97 characters of the original string, followed by three dots.

 

LimitLength(object textObj, int maxLength, string padString, bool wholeWords)

<%# LimitLength("Some example long text", 10 , "...") %>

The same as the method above, while if the last parameter is true, trimming will not be performed in the middle of a word.

 

RemoveDiscussionMacros(object inputText)

<%# RemoveDiscussionMacros("[quote]Sample example text[/quote]") %>

Removes all discussion macros (also referred to as BBCode macros) from the provided text.

 

StripTags(object inputText)

<%# StripTags("Sample text <br />") %>

Removes HTML tags from the provided text.

 

Smart search

 

SearchResultUrl(bool absolute)

<%# SearchResultUrl(true) %>

Returns URL of the current search result document; the only parameter indicates if the returned URL should be absolute. If false, a relative URL is returned.

 

SearchHighlight(string text, string startTag, string endTag)

<%# SearchHighlight("some search result text","<span style=\"background-color: #FEFF8F\">","</span>") %>

Wraps the text entered in the first parameter within the tags specified in the other two parameters.

 

GetSearchImageUrl(string noImageUrl, int maxSideSize)

<%# GetSearchImageUrl("~/App_Themes/Default/Images/CMSModules/SmartSearch/no_image.gif", 90) %>

Returns URL of the current search result image; the first parameter specifies URL returned if no image is found, the second one specifies the maximal side size to which the image will be resized.

 

GetSearchValue(string columnName)

<%# GetSearchValue("DocumentName") %>

Returns the specified column's value for the current search result.

 

Syndication

 

GetAtomDateTime(object dateTime)

<%# GetAtomDateTime(Eval("DocumentCreatedWhen") %>

Returns date and time for Atom feeds (according to RFC 3339) from the provided DateTime object.

 

GetRSSDateTime(object dateTime)

<%# GetRSSDateTime(Eval("DocumentCreatedWhen") %>

Returns date and time for RSS feeds (according to RFC 822) from the provided DateTime object.

 

GetProductUrlForFeed(object skuGUID, object skuName, object siteName)

<%# GetProductUrlForFeed(Eval("SKUGUID"),Eval("SKUName"),Eval("SiteName") %>

Returns URL of the specified product with the feed querystring parameter appended. The product is specified by its SKU GUID in the first parameter and SKU name in the second parameter. The site name provided in the last parameter ensures that correct domain is used in the returned URL.

 

GetDocumentUrlForFeed()

<%# GetDocumentUrlForFeed() %>

This method is used in transformations of RSS and Atom web parts. It returns URL of the rendered document using the GetDocumentUrl() method and adds the feed=<feed_name> querystring parameter to the URL; the feed name is taken from the Feed name web part property.
Please note: as the 'feed' querystring parameter is added when this method is used, please use a different parameter name in the Feed querystring key property of the RSS or Atom web parts in this case.

 

<%# GetForumPostUrlForFeed(object postIdPath, object forumId) %>

<%# GetForumPostUrlForFeed(Eval("PostIDPath"), Eval("PostForumID") %>

Returns URL of the forum post specified by its path in the first parameter and the forum identifier specified in the second parameter, with the feed querystring parameter appended.

 

GetMediaFileUrlForFeed(object fileGUID, object fileName)

<%# GetMediaFileUrlForFeed(Eval("FileGUID"), Eval("FileName") %>

Returns URL of the media file specified by its GUID in the first parameter and its file name in the second parameter, with the feed querystring parameter appended.

 

GetMessageBoardUrlForFeed(object documentIdObj)

<%# GetMessageBoardUrlForFeed("DocumentIdObj") %>

Returns URL of the message board specified by the identifier of the document where the message board is placed, with the feed querystring parameter appended.

 

GetBlogCommentUrlForFeed(object documentIdObj)

<%# GetBlogCommentUrlForFeed(Eval("DocumentID")) %>

Returns URL of comments of the blog post specified by its document identifier, with the feed querystring parameter appended.

 

Other

 

GetAbsoluteUrl(string relativeUrl)

<%# GetAbsoluteUrl("~/Home.aspx") %>

Converts the provided relative URL to an absolute URL.

 

GetBlogCommentsCount(object documentIdObj, string nodeAliasPath)

<%# GetBlogCommentsCount(Eval("DocumentID"), Eval<string>("NodeAliasPath")) %>

Gets the number of comments of the blog post specified by its document identifier in the first parameter and its node alias path in the second parameter.

 

GetBlogCommentsCount(object documentIdObj, string nodeAliasPath, bool includingTrackbacks)

<%# GetBlogCommentsCount(Eval("DocumentID"), Eval<string>("NodeAliasPath"), true) %>

Gets the number of comments of the blog post specified by its document identifier in the first parameter and its node alias path in the second parameter. The last parameter indicates if trackback posts should be included in the result.

 

IfCompare(object value, object comparableValue, object falseResult, object trueResult)

<%# IfCompare(1, 2, "The values are different", "The values are equal") %>

Compares values of the first and the second parameter. If the parameters are different or are both NULL, the third parameter is returned. If they are equal, the fourth parameter is returned.

 

IfEmpty(object value, object emptyResult, object nonEmptyResult)

<%# IfEmpty(Eval("ProductPhoto"), "no image", GetImage("ProductPhoto")) %>

Checks for emptiness of the value specified in the first parameter. If it is NULL, the second parameter is returned. If it has some value, the third parameter is returned.

 

GetNotEmpty(object columnsObj)

<%# GetNotEmpty("FullName;UserName") %>

Returns the first nonEmpty column. A list of column names separated by a semicolon should be provided in the parameter.

 

GetColumnName(string columns)

<%# GetColumnName("column1;column2;column3") %>

Returns the name of the first column which is present and has some value. A list of column names separated by a semicolon should be provided in the parameter.

 

GetColumnName(string columns, bool allowEmptyColumn)

<%# GetColumnName("column1;column2;column3", false) %>

Returns the first column which is present. A list of column names separated by a semicolon should be provided in the first parameter. If the second parameter is true, it does not matter if a column is empty or with some value. If false, only column with some value can be returned.

 

GetDateTimeString(object dateTime, bool showTooltip)

<%# GetDateTimeString(Eval("EventDate"), true) %>

Returns a string representation of date-time with dependence on the current ITimeZone manager time zone settings. If the second parameter is true, the returned string gets wrapped with a tooltip span.

 

GetBadgeImage(int badgeId)

<%# GetBadgeImage(Eval<int>("UserBadgeID")) %>

Returns image tag of the badge whose identifier is provided in the parameter.

 

GetBadgeName(int badgeId)

<%# GetBadgeName(Eval<int>("UserBadgeID")) %>

Returns name of the badge whose identifier is provided in the parameter.

 

Context menus

 

When editing transformations displaying Users or Groups, you can enclose the transformation code within one of the following controls, which enables context menus after right-click on the selected user or group:

 

Users

 

<cms:usermenucontainer runat="server" ID="userMenuElem" MenuID="userContextMenu" Parameter='<%# Eval("UserID").ToString() %>' ContextMenuCssClass="UserContextMenu" >

 

... transformation code ...

 

</cms:usermenucontainer>

 

Groups

 

<cms:groupmenucontainer runat="server" ID="groupMenuElem" MenuID="groupContextMenu" Parameter='<%# Eval("GroupID").ToString() %>' ContextMenuCssClass="UserContextMenu" >

 

... transformation code ...

 

</cms:groupmenucontainer>

 

The code above displays the default context menu controls for users or groups. These controls are stored in <web project>\CMSAdminControls\ContextMenus:

 

GroupContextMenu.ascx
UserContextMenu.ascx

 

You can also develop your custom controls for this purpose. In this case, you need to include the MenuControlPath parameter in the cms:usermenucontainer or cms:groupmenucontainer controls in the transformation and set its value to the path to your control:

 

<cms:groupmenucontainer runat="server" ID="groupMenuElem" MenuID="groupContextMenu" Parameter='<%# Eval("GroupID").ToString() %>' ContextMenuCssClass="UserContextMenu"
MenuControlPath="~\CMSAdminControls\ContextMenus\MyGroupContextMenu.ascx" >

 

... transformation code ...

 

</cms:groupmenucontainer>

 

Page url: http://devnet.kentico.com/docs/5_5r2/contexthelp/index.html?newedit_transformation_methods.htm