Reference - Transformation methods
This reference provides information about the default methods specifically designed for use in transformations:
- Data loading
- Boolean operations
- URLs and document links
- Text manipulation
- Images
- Membership and community
- Date & time
- Smart search
- Syndication (RSS, Atom, XML)
- Microsoft SharePoint
- Placeholders for sublevels in hierarchical data
- Editing buttons for documents displayed by listing web parts
Notes
- All transformation methods return string values (unless otherwise specified).
- The examples of methods below are formatted for ASCX transformations. For Text / XML transformations, macro method equivalents with identical signatures are available for most transformation methods.
- In addition to the listed method, ASCX transformations allow you to call any type of inline code, including ASP.NET system methods, Kentico API or custom API.
- For Text / XML transformations, you can also use general macro methods. See: Reference - Macro methods
Data loading
Method |
Parameters |
Description and examples |
Eval |
|
Loads the value from the specified column of the transformed object’s data. Returns the value as an object data type. Use only for ASCX transformations. The optional boolean parameter specifies whether the method HTML encodes the loaded value (true by default). <%# Eval(“NewsTitle”) %> |
Eval<ReturnType> |
|
Loads the value from a column of the transformed object’s data, and returns it as an object of the specified type. Use only for ASCX transformations. <%# Eval<string>(“NodeAliasPath”) %> |
EvalCDATA |
|
Loads the value from the specified column of the transformed object’s data and escapes all occurrences of the ]]> sequence in the returned string. Depending on the optional boolean parameter (true by default), the method wraps the whole string in the <![CDATA[“wrapped text”]]> enclosure. <%# EvalCDATA(“NewsText”) %> |
EvalJSString |
|
Loads the value from the specified column of the transformed object’s data. Encodes the returned text to be used in JavaScript code and encapsulates it into ’ characters. |
GetEditableValue |
|
Loads the content of an editable region on the page. Specify the region using the control ID (web part control ID). <%# GetEditableValue(“mainText”) %> |
GetNotEmpty |
|
Returns the value of the first data column that is not empty or null. The parameter must provide a list of column names separated by semicolons. <%# GetNotEmpty(“FullName;UserName”) %> |
GetColumnName |
|
Returns the value of the first column that is present in the data of the transformed object. The parameter must provide a list of column names separated by semicolons. By default, the method only returns columns that are not null or empty. Set the optional second parameter to true to allow empty values. |
Property |
Description and examples |
DataItem |
Gets the currently transformed data item. <%# DataItem %> |
DataItemIndex |
Gets the data item index for the current transformation container. You have to use Container.DataItemIndex to get the index in the current binding context. <%# DataItemIndex %> |
DataItemCount |
Gets the total number of data items in the current transformation container. <%# DataItemCount %> |
DataRowView |
Gets a DataRowView of the transformed record’s data. <%# DataRowView[“UserName”] %> |
DisplayIndex |
Gets the current position of the data item as displayed in a control. <%# DisplayIndex %> |
DocumentCustomData |
Gets the value of custom document data fields (culture specific). Use the [“nodename”] notation to retrieve data stored in the specified node of the XML. See also: Storing custom data for all document types <%# DocumentCustomData[“myproperty”] %> |
EditableItems |
Gets the content of the specified editable region on the page. <%# EditableItems[“mainText”] %> |
NodeCustomData |
Gets the value of custom document data fields (shared for all culture versions). Use the [“nodename”] notation to retrieve data stored in the specified node of the XML. See also: Storing custom data for all document types <%# NodeCustomData[“myproperty”] %> |
> Back to the list of transformation method categories
Boolean operations
Method |
Parameters |
Description and examples |
If |
|
Returns a result according to the boolean value of the first parameter. <%# If(Eval(“IsSecuredNode”), “The document requires authentication”, “The document is publicly available”) %> |
IfCompare |
|
Compares the values of the first and the second parameter.
<%# IfCompare(1, 2, “The values are different”, “The values are equal”) %> |
IfEmpty |
|
Checks for emptiness of the value in the first parameter.
<%# IfEmpty(Eval(“ProductPhoto”), “No image”, GetImage(“ProductPhoto”)) %> |
IfTrue |
|
Checks whether the first parameter contains a true boolean value.
|
IsFirst |
- |
Returns a true value if the transformed data item is the first in the provided data. <%# IsFirst() %> |
IsLast |
- |
Returns a true value if the transformed data item is the last in the provided data. <%# IsLast() %> |
IsCurrentDocument |
- |
Returns a true value if the transformed document is equal to the document where the transformation is being displayed. <%# IsCurrentDocument() %> |
IsDocumentOnSelectedPath |
- |
Returns a true value if the transformed document is present on the alias path of the document where the transformation is being displayed (i.e. if the transformed document is an ancestor of the current document). <%# IsDocumentOnSelectedPath() %> |
> Back to the list of transformation method categories
URLs and document links
Method |
Parameters |
Description and examples |
GetAbsoluteUrl |
|
Converts relative URLs to absolute URLs. You can specify the target domain name in the absolute URL using either a site ID, site code name or explicitly. If you leave all optional parameters empty, the method generates the absolute URL using the domain of the current site. <%# GetAbsoluteUrl(“~/Home.aspx”) %> |
GetAttachmentIcon |
|
Returns the attachment file type icon according to the extension of the file identified by the given GUID column. <%# GetAttachmentIcon(“AttachmentGUID”) %> |
GetAttachmentUrl |
|
Returns the URL of the attachment file specified by name in the first parameter, loaded from the document whose alias path matches the second parameter. The method returns the same URL as the GetFileUrl method, but without loading the whole document, which results in better performance. <%# GetAttachmentUrl(Eval<string>(“AttachmentName”), Eval<string>(“NodeAliasPath”)) %> |
GetDocumentLink |
|
Returns a HTML link (<a> tag) that leads to the transformed document. By default, the method HTML encodes the document name in the link title. Set the optional parameter to false to disable the encoding. <%# GetDocumentLink() %> |
GetDocumentUrl |
|
Returns the URL of the specified document. If called without parameters, the method returns the URL of the transformed document. You can optionally specify the document using a document ID. <%# GetDocumentUrl() %> Note: The overload with the document ID parameter is not available as a macro method for Text / XML transformations. Instead, use: {% GetDocumentUrlByID(DocumentID) %} |
GetDocumentUrl |
|
Returns a permanent URL of the specified document (with the NodeGUID in the query string). <%# GetDocumentUrl(Eval(“NodeGUID”), Eval(“NodeAlias”)) %> |
GetFileIcon |
|
Returns the file type icon according to the specified extension. <%# GetFileIcon(Eval(“FileExtension”)) %> |
GetFileUrl |
|
Returns the URL of the attachment file specified by name in the first parameter, loaded from the document whose ID matches the second parameter. <%# GetFileUrl(Eval(“AttachmentFileName”), Eval(“AttachmentDocumentID”)) %> |
GetFileUrl |
|
Returns the URL of the attachment file, specified by an attachment GUID. <%# GetFileUrl(“ProductPhoto”) %> |
GetForumPostUrl |
|
Returns the URL of the forum post specified by the path in the first parameter, from the forum specified by the identifier in the second parameter. <%# GetForumPostUrl(Eval(“PostIDPath”), Eval(“ForumID”)) %> |
GetMediaFileUrl |
|
Returns the URL of the specified media file. The media file is specified by the file GUID in the first parameter and the file name in the second parameter. <%# GetMediaFileUrl(Eval(“FileGUID”) ,Eval(“FileName”)) %> |
GetMetaFileUrl |
|
Returns the URL of the specified meta file. The file is specified by the file GUID in the first parameter and the file name in the second parameter. |
GetProductUrl |
|
Returns the URL of the product specified by an identifier (primary key). <%# GetProductUrl(Eval(“SKUID”)) %> |
GetProductUrl |
|
Returns the URL of the product specified by the GUID in the first parameter, SKU name in the second parameter. <%# GetProductUrl(Eval(“SKUGUID”), Eval(“SKUName”), Eval(“SiteName”) %> |
GetUrl |
|
Returns the URL of the document specified by the alias path in the first parameter or the URL path in the second parameter. <%# GetUrl(Eval(“NodeAliasPath”), Eval(“DocumentUrlPath”)) %> |
> Back to the list of transformation method categories
Text manipulation
Method |
Parameters |
Description and examples |
EnsureMaximumLineLength |
|
Allows you to insert line breaks into long sequences of characters without whitespace (such as URLs). The method places the line break after the number of characters specified by the second parameter. <%# EnsureMaximumLineLength(“VeryLongStringWithoutAnyBlankSpaces”, 21) %> |
HTMLEncode |
|
Encodes HTML tags in the specified text. <%# HTMLEncode(“Sample text <br />”) %> |
LimitLength |
|
Limits text to the length specified in the second parameter. The third parameter is the trimming suffix, i.e. the string appended to the end of shortened strings. The suffix is included in the maximum length. For example, if you use the “…” suffix and a maximum length of 100 characters, the returned string contains the first 97 characters of the original string, followed by an ellipsis. Set the last parameter to true to avoid trimming in the middle of words. <%# LimitLength(“Example of long text”, 10 , “…”, true) %> |
Localize |
|
Resolves all localization expressions inside the specified text. |
RemoveDiscussionMacros |
|
Removes all BBCode tags from the provided text. <%# RemoveDiscussionMacros(“[quote]Sample text[/quote]”) %> |
RemoveDynamicControls |
|
Removes all controls from the specified text (such as inline widgets). <%# RemoveDynamicControls(Eval(“NewsText”) ) %> |
StripTags |
|
Completely removes HTML tags from the specified text. <%# StripTags(“Sample text <br />”) %> |
> Back to the list of transformation method categories
Images
Method |
Parameters |
Description and examples |
GetEditableImage |
|
Returns an image tag that displays the content of an editable image control or web part on the page. Specify the editable image using the control ID (web part control ID). <%# GetEditableValue(“mainImage”) %> |
GetEditableImageUrl |
|
Returns the URL of the image selected inside the specified editable image control or web part. Specify the editable image using the control ID (web part control ID). <%# GetEditableImageUrl(“mainImage”) %> |
GetImage |
|
Returns an image tag that displays the image file whose GUID is stored in the specified column of the transformed object’s data. <%# GetImage(“NewsTeaser”) %> |
GetImageByUrl |
|
Returns an image tag that displays the image stored under the specified URL. <%# GetImageByUrl(“~/Images/Image1.aspx”) %> |
IfImage |
|
Checks whether the document attachment specified by the GUID in the first parameter is an image file. If the file is an image, the method returns the value of the second parameter, otherwise the value of the third parameter. <%# IfImage(“NewsTeaser”, “The file is an image”, “The file is not an image”) %> |
> Back to the list of transformation method categories
Membership and community
Method |
Parameters |
Description and examples |
GetAge |
|
Returns age calculated 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. <%# GetAge(Eval(“UserDateOfBirth”),“Unknown age”) %> |
GetBadgeImage |
|
Returns an image tag that displays the specified user badge. <%# GetBadgeImage(Eval<int>(“UserBadgeID”)) %> |
GetBadgeName |
|
Returns the display name of the specified badge. <%# GetBadgeName(Eval<int>(“UserBadgeID”)) %> |
GetGender |
|
Returns the gender of users according to the value specified in the parameter. Load the value from the user’s gender field.
<%# GetGender(Eval(“UserGender”)) %> |
GetGroupAvatarImage |
|
Returns an image tag that displays the avatar of a group. The group is either identified automatically using the AvatarGuid field of the transformed group, or you can optionally specify an identifier value using the first parameter. <%# GetGroupAvatarImage(200, “Alternate text”) %> |
GetGroupProfileUrl |
|
Returns the URL of the specified group’s profile page. <%# GetGroupProfileUrl(Eval(“GroupName”) %> |
GetMemberProfileUrl |
|
Returns the URL of the user profile page for the specified group member. <%# GetMemberProfileUrl(Eval(“UserName”)) %> |
GetUserAvatarImage |
|
Returns an image tag that displays the avatar of a user. The user is either identified automatically using the AvatarGuid field of the transformed user, or you can specify either an avatar identifier or user identifier. <%# GetUserAvatarImage(200, “Alternate text”) %> |
GetUserAvatarImageUrl |
|
Returns the URL of the specified user’s avatar image. If the user does not have an avatar, the method returns the URL of the default avatar image. <%# GetUserAvatarImageUrl(Eval(“UserAvatarID”), Eval(“UserID”), 200, 150, 150) %> |
GetUserFullName |
|
Returns the full name of the specified user. <%# GetUserFullName(Eval<int>(“UserID”)) %> |
GetUserProfileUrl |
|
Returns the URL of the user profile page for the specified user. <%# GetUserProfileURL(Eval(“UserName”)) %> |
TrimSitePrefix |
|
Removes the site prefix from user names (if site prefixes are enabled in Settings -> Security & Membership -> Use site prefix for user names). |
> Back to the list of transformation method categories
Date & time
Method |
Parameters |
Description and examples |
FormatDate |
|
Displays the specified date without the time component. The method automatically formats the date according to the current culture. <%# FormatDate(DateTime.Now) %> |
FormatDateTime |
|
Displays the date and time value according to a format string. The method formats the date and time according to the current culture. <%# FormatDateTime(DateTime.Now, “MM/dd/yyyy HH:mm”) %> |
GetDate |
|
Loads a date value from the specified field of the transformed object’s data. <%# GetDate(“NewsReleaseDate”) %> |
GetDateTime |
|
Loads a date and time value from the specified field of the transformed object’s data. The value uses the time zone set for the server. Optionally, you can format the date and time value according to a format string. <%# GetDateTime(“NewsReleaseDate”) %> |
GetCustomDateTime |
|
Converts a date and time value to the specified time zone. <%# GetCustomDateTime(DateTime.Now, “GreenwichMeanTime”) %> |
GetDateTimeString |
|
Converts the specified date and time value to the time zone set for the server. The second parameter determines whether the displayed date and time has a tooltip. <%# GetDateTimeString(“NewsReleaseDate”, true) %> |
GetSiteDateTime |
|
Converts the specified date and time value to the current site’s time zone. <%# GetSiteDateTime(Eval(“NewsReleaseDate”)) %> |
GetUserDateTime |
|
Converts the specified date and time value to the time zone set for the user viewing the page. <%# GetUserDateTime(Eval(“NewsReleaseDate”)) %> |
> Back to the list of transformation method categories
Smart search
See Setting up search on your website for more information.
Method |
Parameters |
Description and examples |
SearchResultUrl |
|
Returns the URL of the page containing the details of the search result. The optional parameter indicates if the returned URL is absolute. |
SearchHighlight |
|
Wraps the text of the first parameter into the tags specified by the other two parameters. <%# SearchHighlight(SearchResultUrl(),“<strong>”,“</strong>”)%> |
GetSearchImageUrl |
|
Returns the URL of the current search result’s image. The first parameter specifies the URL used if no image is found – enter either the full relative path starting from the application root (~/), or a partial path starting from the ~/App_Themes/<skin_folder>/Images/ directory. The second parameter specifies the maximum side size to which the method resizes the image. <%# GetSearchImageUrl(“~/App_Themes/Default/Images/CMSModules/CMS_SmartSearch/no_image.gif”, 90) %> <%# GetSearchImageUrl(“/CMSModules/CMS_SmartSearch/no_image.gif”, 90) %> |
GetSearchValue |
|
Returns the value of the specified field for the current search result. Allows you to access both the general fields of the given objects type (document, custom table etc.) and any other fields included in the search index. <%# GetSearchValue(“DocumentName”) %> |
GetSearchedContent |
|
Parses the searched content as XML if required, and removes dynamic controls and macro expressions. |
> Back to the list of transformation method categories
Syndication (RSS, Atom, XML)
See also: Setting up syndication feeds
Method |
Parameters |
Description and examples |
GetAtomDateTime |
|
Returns the specified date and time value in a format suitable for Atom feeds (according to RFC 3339). <%# GetAtomDateTime(Eval(“DocumentCreatedWhen”)) %> |
GetRSSDateTime |
|
Returns the specified date and time value in a format suitable for RSS feeds (according to RFC 882). <%# GetRSSDateTime(Eval(“DocumentCreatedWhen”)) %> |
GetBlogCommentUrlForFeed |
|
Returns the URL of the comments added to the blog post specified by a document identifier. Includes the feed query string parameter in the URL. <%# GetBlogCommentUrlForFeed(Eval(“DocumentID”)) %> |
GetDocumentUrlForFeed |
- |
Returns the URL of the transformed document with the feed query string parameter in the URL. The method takes the feed name from the Feed name property of the syndication web part used to generate the feed. Note: Since the method adds the feed query string parameter, please use a different parameter name in the Feed querystring key property of the syndication web part. <%# GetDocumentUrlForFeed() %> |
GetForumPostUrlForFeed |
|
Returns the URL of the forum post specified by the path in the first parameter and the forum identifier in the second parameter. Includes the feed query string parameter in the URL. <%# GetForumPostUrlForFeed(Eval(“PostIDPath”), Eval(“PostForumID”)) %> |
GetMediaFileUrlForFeed |
|
Returns the URL of the media file specified by the GUID in the first parameter and the file name in the second parameter. Includes the feed query string parameter in the URL. <%# GetMediaFileUrlForFeed(Eval(“FileGUID”), Eval(“FileName”)) %> |
GetMessageBoardUrlForFeed |
|
Returns the URL of the message board specified by the identifier of the document containing the message board. Includes the feed query string parameter in the URL. <%# GetMessageBoardUrlForFeed(“DocumentIdObj”) %> |
GetProductUrlForFeed |
|
Returns the URL of the specified product with the feed query string parameter in the URL. The product is specified by the SKU GUID in the first parameter and SKU name in the second parameter. The site name provided in the last parameter ensures that the correct domain is used in the returned URL. <%# GetProductUrlForFeed(Eval(“SKUGUID”),Eval(“SKUName”),Eval(“SiteName”)) %> |
> Back to the list of transformation method categories
Microsoft SharePoint
See also: SharePoint integration
Method |
Parameters |
Description and examples |
GetSharePointFileUrl OR GetSPFileUrl |
|
Returns the URL of 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. <%# GetSharePointFileUrl(“server”, SharePointFunctions.SplitSharePointField((string)Eval(“ows_FileRef”), 1)) %> |
SplitSharePointField OR SplitSPField |
|
Helper function for splitting combined fields returned by SharePoint. For example, 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. <%# SplitSharePointField((string)Eval(“ows_FileRef”), 1)) %> |
> Back to the list of transformation method categories
Placeholders for sublevels in hierarchical data
If you are writing transformations for items from a hierarchical data source (for example document data from the Universal viewer web part), you can add a placeholder that sets the position of sublevels:
For ASCX transformations:
<cms:SubLevelPlaceHolder runat="server" ID="plcSub" />
For Text transformations:
{^SubLevelPlaceHolder^}
When displaying items that have descendants in the hierarchy, the placeholder is replaced by the child level under the given item. If you do not add the sublevel placeholder, the system automatically renders child levels after the code of parent items.
You can use the sublevel placeholder in hierarchical transformations, as well as standard transformations applied to hierarchical data.
Note: The sublevel placeholder only works if the Hierarchical display mode property of the viewer web part is set to Inner.
> Back to the list of transformation method categories
Editing buttons for documents displayed by listing web parts
You can configure listing web parts (such as the Repeater) to display special buttons in editing mode (on the Page tab of the Pages application). The buttons allow users to edit or delete individual items displayed in the list.
To set the exact position of the editing buttons, add the following expression into the code of ASCX item transformations:
##editbuttons##