---
title: Reference - Macro methods
related:
  - https://docs.kentico.com/13/macro-expressions/macro-syntax.md
  - https://docs.kentico.com/13/macro-expressions/extending-the-macro-engine/registering-custom-macro-methods.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

&#x20;Macro expressions allow you to use a large variety of methods. The following categories list the methods according to the type of provided functionality:

> **Info:** The macro syntax allows you to use infix notation for the first parameter of methods.
>
> For example:  _**{% "word".ToUpper() %}**_  instead of  _**{% ToUpper("word") %}**_

## Data manipulation

| Method             | Return type           | Parameters                                                                                                                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GetValue           | object                | ISimpleDataContainer container<br>string column<br>_object defaultValue_                                                                                     | Gets the value of the specified data column of an object that implements the ISimpleDataContainer interface. You can specify a default value used if the requested data is null.<br>Example:<br>_{% Documents\["/Articles"].GetValue("Title") %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| GetProperty        | object                | IHierarchicalObject object<br>string property<br>_object defaultValue_                                                                                       | Gets the value of the specified property of an IHierarchicalObject object. You can specify a default value used if the requested property is null.<br>Example:<br>_{% Documents\["/Articles"].GetProperty("Title") %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| GetItem            | object                | IEnumerable collection<br>int index<br>_object defaultValue_                                                                                                 | Gets the object at the specified index of a collection. You can specify a default value used if the requested object is null.<br>Example:<br>_{% GlobalObjects.Users.GetItem(0).UserName %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| OrderBy            | IInfoObjectCollection | IInfoObjectCollection collection<br>string orderBy                                                                                                           | Returns the collection of objects, with the order defined by the specified SQL ORDER BY clause.<br>If the macro is saved by a user without the Administrator [privilege level](https://docs.kentico.com/13/managing-users/user-management.md), the method only allows the following SQL syntax:<br>one or more column names (separated by commas)<br>the ASC and DESC keywords<br>Example:<br>_{% GlobalObjects.Users.OrderBy("UserCreated DESC").FirstItem.UserName %}_                                                                                                                                                                                                                                                                                                |
| Where              | IInfoObjectCollection | IInfoObjectCollection collection<br>string where                                                                                                             | Filters a collection of objects according to the specified SQL Where condition.<br>If the macro is saved by a user without the Administrator [privilege level](https://docs.kentico.com/13/managing-users/user-management.md), the method only allows the following SQL syntax in the where condition:<br>column names, values and basic operators: =, !=, >, <<br>AND & OR operators, parentheses<br>_column_ BETWEEN _value_ AND _value_<br>_column_ LIKE _value_<br>_column_ IN _(values)_<br>_column_ IS NULL<br>NOT keyword for the above expressions (NOT BETWEEN, NOT LIKE, NOT IN, IS NOT NULL)<br>Other expressions and SQL functions are not supported.<br>Example:<br>_{% GlobalObjects.Users.Where("Email LIKE '%@localhost.local'").FirstItem.UserName %}_ |
| TopN               | IInfoObjectCollection | IInfoObjectCollection collection<br>int topn                                                                                                                 | Returns only the specified number of objects in the collection.<br>Example:<br>_{% GlobalObjects.Users.TopN(1).FirstItem.UserName %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Columns            | IInfoObjectCollection | IInfoObjectCollection collection<br>string columns                                                                                                           | Returns the collection of objects containing only the specified data columns.<br>If the macro is saved by a user without the Administrator [privilege level](https://docs.kentico.com/13/managing-users/user-management.md), the method only allows the following SQL syntax:<br>one or more column names (separated by commas)<br>SQL aliases for columns defined using the AS keyword (must be upper case)<br>Example:<br>_{% GlobalObjects.Users.Columns("UserName, Email").FirstItem.UserName %}_                                                                                                                                                                                                                                                                   |
| Filter             | IList                 | IEnumerable collection<br>MacroExpression condition                                                                                                          | Filters a collection of objects according to the specified macro condition.<br>Example:<br>_{% GlobalObjects.Users.Filter(UserID == 53).FirstItem.UserName %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ClassNames         | TreeNodeCollection    | TreeNodeCollection collection<br>string classNames                                                                                                           | Filters a TreeNodeCollection of pages according to the specified [page types](https://docs.kentico.com/13/developing-websites/defining-website-content-structure/managing-page-types.md). The second parameter must contain a list of allowed page type code names, separated by semicolons.<br>Example:<br>_{% Documents.ClassNames("site.article;site.news").Count %}_                                                                                                                                                                                                                                                                                                                                                                                                |
| InList             | bool                  | object object<br>IEnumerable collection                                                                                                                      | Returns a true value if the object exists within the specified collection.<br>Example:<br>_{% Documents\["/Articles"].ClassName.InList("site.article,cms.root".Split(",")) %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| All                | bool                  | IEnumerable collection<br>MacroExpression condition                                                                                                          | Returns a true value if all of the objects in the collection match the given condition. Specify the condition as a macro expression.<br>Example:<br>_{% GlobalObjects.Users.All(UserEnabled == true) %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Any                | bool                  | IEnumerable collection<br>MacroExpression _condition_                                                                                                        | Returns a true value if at least one object in the collection matches the given condition. Specify the condition as a macro expression.<br>If you leave out the condition parameter, the method returns true if the collection contains at least one object.<br>Throws an exception if the collection is null.<br>Example:<br>_{% GlobalObjects.Users.Any(UserEnabled == false) %}_                                                                                                                                                                                                                                                                                                                                                                                     |
| Exists             | bool                  | IEnumerable collection<br>MacroExpression _condition_                                                                                                        | Returns a true value if at least one object in the collection matches the given condition. Specify the condition as a macro expression.<br>If you leave out the condition parameter, the method returns true if the collection contains at least one object.<br>Returns false if the collection is null.<br>Example: _{% GlobalObjects.Users.Exists(UserEnabled == false) %}_                                                                                                                                                                                                                                                                                                                                                                                           |
| RandomSelection    | IList                 | IEnumerable items<br>_int numberOfItems_                                                                                                                     | Returns randomly selected objects from the collection. You can optionally specify the number of items.<br>Example:<br>_{% GlobalObjects.Users.RandomSelection().UserName %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| SelectInterval     | IList                 | IEnumerable items<br>int lowerBound<br>int upperBound                                                                                                        | Returns the specified interval of objects from the collection.<br>Example:<br>_{% Documents.SelectInterval(0,9) %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Cache              | object                | object expression<br>_int cacheMinutes_<br>_bool condition_<br>_string cacheItemName_<br>_string cacheItemNameParts_<br>_CMSCacheDependency cacheDependency_ | Evaluates the specified macro expressions and stores the result in the server-side application cache. The system only evaluates the expression if the result is not found in the cache.<br>See also: [Caching the results of macros](https://docs.kentico.com/13/macro-expressions/caching-the-results-of-macros.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| GetCacheDependency | CMSCacheDependency    | string\[] dependencies                                                                                                                                       | Returns a CMSCacheDependency object based on the specified dummy cache keys (one or more string parameters).<br>See also:<br>[Setting cache dependencies](https://docs.kentico.com/13/configuring-xperience/configuring-caching/setting-cache-dependencies.md)<br>[Caching the results of macros](https://docs.kentico.com/13/macro-expressions/caching-the-results-of-macros.md)                                                                                                                                                                                                                                                                                                                                                                                       |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Data conversion

| Method     | Return type | Parameters                                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ---------- | ----------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ToString   | string      | object value<br>_string defaultValue_<br>_string culture_<br>_string format_ | Converts an object to a string. Returns the optional default value if the conversion is not possible.<br>You can also specify the culture context and a formatting string used for the conversion.<br>Examples:<br>_{% DocumentName.ToString() %}_<br>_{% DocumentName.ToString("defaultValue") %}_<br>_{% DocumentName.ToString("defaultValue", "en-US") %}_<br>_{% DocumentName.ToString("defaultValue", DocumentCulture, "Document name is: {0}") %}_ |
| ToInt      | int         | object value<br>_int defaultValue_                                           | Converts an object to an integer number. Returns the optional default value if the conversion is not possible.<br>Example: _{% DocumentID.ToInt() %}_                                                                                                                                                                                                                                                                                                    |
| ToBool     | bool        | object value<br>_bool defaultValue_                                          | Converts an object to a boolean value. Returns the optional default value if the conversion is not possible.<br>Example: _{% DocumentShowInSiteMap.ToBool() %}_                                                                                                                                                                                                                                                                                          |
| ToDecimal  | decimal     | object value<br>_decimal defaultValue_<br>_string culture_                   | Converts an object to a decimal number. Returns the optional default value if the conversion is not possible.<br>You can also specify a culture code to determine the formatting of the decimal number.<br>Examples:<br>_{% DocumentID.ToDecimal() %}_<br>_{% DocumentID.ToDecimal("0.0", DocumentCulture) %}_                                                                                                                                           |
| ToDouble   | double      | object value<br>_double defaultValue_<br>_string culture_                    | Converts an object to a double number. Returns the optional default value if the conversion is not possible.<br>You can also specify a culture code to determine the formatting of the double number.<br>Examples:<br>_{% DocumentID.ToDouble() %}_<br>_{% DocumentID.ToDouble("0.0", DocumentCulture) %}_                                                                                                                                               |
| ToGuid     | guid        | object value<br>_Guid defaultValue_                                          | Converts an object to a [GUID value](http://en.wikipedia.org/wiki/Guid). Returns the optional default value if the conversion is not possible.<br>Example: _{% DocumentGUID.ToGuid() %}_                                                                                                                                                                                                                                                                 |
| ToDateTime | DateTime    | object value<br>_DateTime defaultValue_<br>_string culture_                  | Converts an object to a DateTime value. Returns the optional default value if the conversion is not possible.<br>You can also specify a culture code to determine the date format.<br>Example: _{% ToDateTime(_"12/31/2017 11:59 PM"_) %}_                                                                                                                                                                                                               |
| FromOADate | DateTime    | double value                                                                 | Converts a double representation of a date and time value (OLE Automation Date) to a DateTime object.<br>Example: _{% FromOADate(43100.999305556) %}_                                                                                                                                                                                                                                                                                                    |
| ToTimeSpan | TimeSpan    | object value                                                                 | Converts an object to a TimeSpan value. Returns null if the conversion is not possible.<br>Example: _{% ToTimeSpan("1:00:00") %}_                                                                                                                                                                                                                                                                                                                        |
| ToBaseInfo | BaseInfo    | object value<br>_BaseInfo defaultValue_                                      | Converts an object to a BaseInfo – the general type for Xperience system objects and pages. Returns the optional default value if the conversion is not possible.<br>Example: _{% CurrentUser.ToBaseInfo() %}_                                                                                                                                                                                                                                           |
| List       | ArrayList   | object items                                                                 | Converts a list of objects to an ArrayList.<br>Example: _{% List("Apple", "Orange", "Banana") %}_                                                                                                                                                                                                                                                                                                                                                        |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Text manipulation

| Method                  | Return type | Parameters                                                           | Description                                                                                                                                                                                                                                                                                                                                                 |
| ----------------------- | ----------- | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Contains                | bool        | string text<br>string search                                         | Returns a true value if the string specified by the second parameter occurs within the first string.                                                                                                                                                                                                                                                        |
| EndsWith                | bool        | string text<br>string findText                                       | Indicates whether the string specified by the second parameter occurs at the end of the first string.                                                                                                                                                                                                                                                       |
| EnsureMaximumLineLength | string      | object textObj<br>int maxLength                                      | Inserts 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.<br>The method does not support text containing HTML tags.                                                                                                       |
| Format                  | string      | string value<br>string format                                        | Replaces all formatting expressions in a string using the text equivalents specified in the second parameter.<br>Based on [composite formatting](https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting).                                                                                                                         |
| FormatNotEmpty          | string      | string value<br>string format<br>_string emptyResult_                | If the first parameter is not empty or null, replaces all formatting expressions in the string using the text equivalents specified in the second parameter. Returns the optional third parameter if the value is null or empty.<br>Based on [composite formatting](https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting).      |
| GetEmailDomain          | string      | string email                                                         | Returns the domain segment from the specified email address value.                                                                                                                                                                                                                                                                                          |
| GetMatch                | string      | string text<br>string regex                                          | Matches the string value to the specified regular expression and returns the match.                                                                                                                                                                                                                                                                         |
| IndexOf                 | int         | string text<br>string searchFor                                      | Returns the index of the first occurrence of the second string within the first string.                                                                                                                                                                                                                                                                     |
| LastIndexOf             | int         | string text<br>string searchFor                                      | Returns the index of the last occurrence of the second string within the first string.                                                                                                                                                                                                                                                                      |
| LimitLength             | string      | string text<br>int length<br>_string padString_<br>_bool wholeWords_ | Limits the length of the string to the specified number of characters.<br>The _padString_ parameter allows you to set a string that the method appends to the end of the limited result. The length of the parameter is included in the maximum length.<br>If you set the _wholeWords_ parameter to true, the method preserves the last word in the string. |
| LoremIpsum              | string      | _int length_                                                         | Generates [lorem Ipsum](http://en.wikipedia.org/wiki/Lorem_ipsum) text. You can specify the number of generated characters (1000 by default).                                                                                                                                                                                                               |
| Matches                 | bool        | string text<br>string regex                                          | Indicates whether the string matches the specified regular expression.                                                                                                                                                                                                                                                                                      |
| NotContains             | bool        | string text<br>string search                                         | Returns a true value if the string specified by the second parameter does NOT occur within the first string.                                                                                                                                                                                                                                                |
| PadLeft                 | string      | string text<br>int length<br>_string paddingString_                  | Adds leading characters to the string until the total length matches the second parameter.<br>By default, the method uses spaces as the padding character, but you can optionally specify a different character.                                                                                                                                            |
| PadRight                | string      | string text<br>int length<br>_string paddingString_                  | Adds trailing characters to the string until the total length matches the second parameter.<br>By default, the method uses spaces as the padding character, but you can optionally specify a different character.                                                                                                                                           |
| RegexReplace            | string      | string text<br>string regex<br>string replacement                    | Replaces strings that match the regular expression pattern within the first string using the replacement string.                                                                                                                                                                                                                                            |
| Remove                  | string      | string text<br>int position<br>_int length_                          | Deletes characters from the string, starting at the specified index. By default, the method removes all remaining characters from the specified position. You can optionally specify the number of characters to be removed.                                                                                                                                |
| Replace                 | string      | string text<br>string replace<br>string replacement                  | Replaces all occurrences of the second string within the first string using the replacement string.                                                                                                                                                                                                                                                         |
| Split                   | string\[]   | string text<br>string delimiters<br>_bool removeEmpty_               | Separates the string into an array of substrings according to the specified delimiting characters. If the optional third parameter is true, the method removes empty substrings from the result.                                                                                                                                                            |
| StartsWith              | bool        | string text<br>string findText                                       | Indicates whether the string specified by the second parameter occurs at the start of the first string.                                                                                                                                                                                                                                                     |
| Substring               | string      | string text<br>int index<br>_int length_                             | Returns a substring starting at the specified index. By default, the method returns all remaining characters from the specified index. You can optionally specify the number of characters to be returned.                                                                                                                                                  |
| ToLower                 | string      | string text                                                          | Converts the entire string to lower case.                                                                                                                                                                                                                                                                                                                   |
| ToUpper                 | string      | string text                                                          | Converts the entire string to upper case.                                                                                                                                                                                                                                                                                                                   |
| Trim                    | string      | string text<br>_string charsToTrim_                                  | Removes all leading and trailing occurrences of characters from the string. By default, the method trims white space characters, but you can optionally specify a different set of characters (as a string).                                                                                                                                                |
| TrimEnd                 | string      | string text<br>_string charsToTrim_                                  | Removes all trailing occurrences of characters from the string. By default, the method trims white space characters, but you can optionally specify a different set of characters (as a string).                                                                                                                                                            |
| TrimStart               | string      | string text<br>_string charsToTrim_                                  | Removes all leading occurrences of characters from the string. By default, the method trims white space characters, but you can optionally specify a different set of characters (as a string).                                                                                                                                                             |

> **Tip:** **Tips**: To perform lexicographical comparison of strings, use the basic comparison operators (==, , =).  Add [macro parameters](https://docs.kentico.com/13/macro-expressions/macro-syntax.md#macro-parameters) to specify case sensitivity and the culture context of text operations.

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Advanced text processing

| Method                  | Return type | Parameters                                   | Description                                                                                                                                                                                                                                                                                                                                   |
| ----------------------- | ----------- | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GetResourceString       | string      | string resourceStringKey<br>_string culture_ | Translates the specified [resource (localization) string](https://docs.kentico.com/13/multilingual-websites/setting-up-a-multilingual-user-interface/working-with-resource-strings.md). By default, the target language of the localization depends on the current culture. You can specify the target language using the optional parameter. |
| HTMLEncode              | string      | string text                                  | Encodes HTML tags in the specified text. For example:<br>_{% HTMLEncode("Sample text ") %}_                                                                                                                                                                                                                                                   |
| JSEscape                | string      | string text                                  | Escapes the string for safe usage in JavaScript. Adds the \ escape character before special characters used by JavaScript (quotes, etc.).<br>Note: The _JSEscape_ method is not available when resolving macros in an external application using the _Kentico.Xperience.Libraries_ NuGet package.                                             |
| Localize                | string      | string inputText<br>_string culture_         | Resolves [localization expressions](https://docs.kentico.com/13/multilingual-websites/setting-up-a-multilingual-user-interface/localizing-text-fields.md) within the specified text. By default, the target language of the localization depends on the current culture. You can specify the target language using the optional parameter.    |
| MapPath                 | string      | string path                                  | Returns the physical file path that matches the specified virtual path.                                                                                                                                                                                                                                                                       |
| ResolveBBCode           | string      | string text                                  | Resolves BBCode tags in the specified text, for example:<br>_{% ResolveBBCode("\[quote]Sample text\[/quote]") %}_                                                                                                                                                                                                                             |
| ResolveMacroExpressions | string      | string expression                            | Resolves the specified macro expression (without the _{% %}_ parentheses).                                                                                                                                                                                                                                                                    |
| ResolveMacros           | string      | string inputText                             | Resolves all macros within the specified text.                                                                                                                                                                                                                                                                                                |
| StripTags               | string      | string text                                  | Removes all HTML tags from the specified text.<br>Does not remove [HTML Entities](https://www.w3schools.com/html/html_entities.asp), such as _<_                                                                                                                                                                                              |
| SQLEscape               | string      | string text                                  | Escapes the string for safe usage in SQL commands (to avoid SQL injection).                                                                                                                                                                                                                                                                   |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Page and file URLs

| Method                        | Return type | Parameters                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ----------------------------- | ----------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GetMediaFileDirectPath        | string      | int libraryId<br>string filePath                                     | Returns the direct URL to the specified [media library file](https://docs.kentico.com/13/managing-website-content/working-with-files/media-library-files.md) on the file system, as a relative URL path. For example:<br>_\~/MySite/media/CoffeeGallery/sample\_image.jpg_<br>The file is identified by the ID of the media library containing the file (the value in the media file's _FileLibraryID_ column) and the file's media library path and extension (the value in the media file's _FilePath_ column).<br>The method does NOT check the permissions of users to view the given file.<br>Example:<br>_{% GetMediaFileDirectPath(FileLibraryID, FilePath) %}_                                                                                                                                                                       |
| GetMediaFileRelativePath      | string      | Guid fileGUID<br>string fileName                                     | Returns the permanent URL for the specified [media library file](https://docs.kentico.com/13/managing-website-content/working-with-files/media-library-files.md), as a relative URL path. The file is identified by its GUID identifier (the value in the media file's _FileGuid_ column), and the resulting URL includes the specified file name. For example:<br>_\~/getmedia/9707c8ff-cd3d-4045-b697-a7d012093cd6/sampleImage_<br>The method evaluates the permissions of the current user to view the given file.<br>Example:<br>_{% GetMediaFileRelativePath(FileGuid, FileName) %}_                                                                                                                                                                                                                                                    |
| ResolveUrl                    | string      | string url                                                           | Converts relative virtual URLs starting with \~/ to relative URLs containing the current application path (so they can be resolved by clients). Absolute URLs remain unchanged.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| UnresolveUrl                  | string      | string url                                                           | Converts relative URLs containing the application path to relative virtual URLs starting with \~/. Absolute URLs remain unchanged.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| UrlEncode                     | string      | string url                                                           | Applies URL encoding to the specified string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Url.GetAttachmentRelativePath | string      | Guid attachmentGuid<br>string attachmentFileName<br>_string variant_ | Returns the relative URL path of the page attachment file specified by an attachment GUID value. For example, you can use the method to work with [grouped](https://docs.kentico.com/13/developing-websites/defining-website-content-structure/managing-page-types/configuring-grouped-page-attachments.md) and [unsorted](https://docs.kentico.com/13/managing-website-content/working-with-files/page-attachments.md) attachments. You can optionally generate a URL for an [image variant](https://docs.kentico.com/13/developing-websites/managing-responsive-images.md) of the attachment by specifying an image variant definition identifier.<br>Note: The method must always be called from the **Url** macro namespace, using prefix notation.<br>Example:<br>_{% Url.GetAttachmentRelativePath(AttachmentGUID, AttachmentName) %}_ |
| Url.GetDocumentRelativePath   | string      | int documentId                                                       | Returns the relative live site URL path of the specified page (the page is identified by its ID).<br>Note: The method must always be called from the **Url** macro namespace, using prefix notation.<br>Example:<br>_{% Url.GetDocumentRelativePath(Documents\["/Articles"].DocumentID) %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Url.MakeAbsolute              | string      | string relativeUrl<br>int siteId<br>_string cultureCode_             | Converts relative virtual URLs to absolute URLs, based on the live site (presentation) URL of the specified site. For sites that use different presentation [domain aliases for specific cultures](https://docs.kentico.com/13/multilingual-websites/setting-up-multilingual-websites/configuring-urls-for-multilingual-websites.md), you can optionally set the culture.<br>Note: The method must always be called from the **Url** macro namespace, using prefix notation.<br>Examples:<br>_{% Url.MakeAbsolute(GetMediaFileDirectPath(FileLibraryID, FilePath), CurrentSite.SiteID) %}_<br>_{% Url.MakeAbsolute(Url.GetDocumentRelativePath(Documents\["/Articles"].DocumentID), CurrentSite.SiteID) %}_                                                                                                                                  |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Date and time

| Method            | Return type | Parameters                               | Description                                                                                                                                                                                                                                                                                                                    |
| ----------------- | ----------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| AddMilliseconds   | DateTime    | DateTime datetime<br>int milliseconds    | Adds the specified number of milliseconds to a DateTime value.                                                                                                                                                                                                                                                                 |
| AddSeconds        | DateTime    | DateTime datetime<br>int seconds         | Adds the specified number of seconds to a DateTime value.                                                                                                                                                                                                                                                                      |
| AddMinutes        | DateTime    | DateTime datetime<br>int minutes         | Adds the specified number of minutes to a DateTime value.                                                                                                                                                                                                                                                                      |
| AddHours          | DateTime    | DateTime datetime<br>int hours           | Adds the specified number of hours to a DateTime value.                                                                                                                                                                                                                                                                        |
| AddDays           | DateTime    | DateTime datetime<br>int days            | Adds the specified number of days to a DateTime value.                                                                                                                                                                                                                                                                         |
| AddWeeks          | DateTime    | DateTime datetime<br>int weeks           | Adds the specified number of weeks to a DateTime value.                                                                                                                                                                                                                                                                        |
| AddMonths         | DateTime    | DateTime datetime<br>int months          | Adds the specified number of months to a DateTime value.                                                                                                                                                                                                                                                                       |
| AddYears          | DateTime    | DateTime datetime<br>int years           | Adds the specified number of years to a DateTime value.                                                                                                                                                                                                                                                                        |
| FormatDate        | string      | DateTime dateTime                        | Displays the specified date without the time component. The method automatically formats the date according to the current culture context.<br>For example:<br>_{% FormatDate(DateTime.Now) %}_                                                                                                                                |
| FormatDateTime    | string      | DateTime dateTime<br>string format       | Displays the date and time value according to a [format string](https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings). The method formats the date and time according to the current culture context.<br>For example:<br>_{% FormatDateTime(DateTime.Now, "MM/dd/yyyy HH:mm") %}_ |
| GetCustomDateTime | DateTime    | DateTime dateTime<br>string timeZoneName | Converts a date and time value to a specific [time zone](https://docs.kentico.com/13/configuring-xperience/configuring-time-zones.md) (identified by the time zone code name).<br>For example:<br>_{% GetCustomDateTime(DateTime.Now, "GreenwichMeanTime") %}_                                                                 |
| GetSiteDateTime   | DateTime    | DateTime dateTime                        | Converts the specified date and time value to the current site's [time zone](https://docs.kentico.com/13/configuring-xperience/configuring-time-zones.md).                                                                                                                                                                     |
| GetUserDateTime   | DateTime    | DateTime dateTime                        | Converts the specified date and time value to the [time zone](https://docs.kentico.com/13/configuring-xperience/configuring-time-zones.md) set for the current user.                                                                                                                                                           |
| ToShortDateString | string      | DateTime datetime                        | Converts the value of the DateTime parameter to an equivalent short date string representation.                                                                                                                                                                                                                                |
| ToShortTimeString | string      | DateTime datetime                        | Converts the value of the DateTime parameter to an equivalent short time string representation.                                                                                                                                                                                                                                |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Mathematical operations

> **Info:** The [macro autocomplete help](https://docs.kentico.com/13/macro-expressions/entering-macro-expressions.md) only shows the mathematical methods as members of the **Math** namespace, for example _{% Math.Abs(-2) %}_. However, the system resolves the methods even without the namespace.

| Method          | Return type | Parameters                                           | Description                                                                                                                                                                                                                                                                                                                                                                                |
| --------------- | ----------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Abs             | double      | double number                                        | The absolute value of the specified number.                                                                                                                                                                                                                                                                                                                                                |
| Acos            | double      | double number                                        | The angle whose cosine is the specified number.                                                                                                                                                                                                                                                                                                                                            |
| Asin            | double      | double number                                        | The angle whose sine is the specified number.                                                                                                                                                                                                                                                                                                                                              |
| Atan            | double      | double number                                        | The angle whose tangent is the specified number.                                                                                                                                                                                                                                                                                                                                           |
| Average         | double      | InfoObjectCollection collection<br>string columnName | The average of all numbers in the specified data column of the objects in the collection.                                                                                                                                                                                                                                                                                                  |
| Ceiling         | double      | double number                                        | The smallest whole number greater than or equal to the specified number.                                                                                                                                                                                                                                                                                                                   |
| Cos             | double      | double number                                        | The cosine of the specified angle.                                                                                                                                                                                                                                                                                                                                                         |
| Cosh            | double      | double number                                        | The hyperbolic cosine of the specified angle.                                                                                                                                                                                                                                                                                                                                              |
| Exp             | double      | double number                                        | **e** raised to the specified power.                                                                                                                                                                                                                                                                                                                                                       |
| Floor           | double      | double number                                        | The largest whole number lesser than or equal to the specified number.                                                                                                                                                                                                                                                                                                                     |
| GetRandomInt    | int         | _int minValue_<br>_int maxValue_<br>_int seed_       | Generates a random positive integer. You can use the optional parameters to specify the range of possible numbers, and the seed number for the generator.                                                                                                                                                                                                                                  |
| GetRandomDouble | double      | _int minValue_<br>_int maxValue_<br>_int seed_       | Generates a random positive decimal number. You can use the optional parameters to specify the range of possible numbers, and the seed number for the generator.                                                                                                                                                                                                                           |
| IsOdd           | bool        | int number                                           | Returns a true value if the specified number is odd.                                                                                                                                                                                                                                                                                                                                       |
| IsEven          | bool        | int number                                           | Returns a true value if the specified number is even.                                                                                                                                                                                                                                                                                                                                      |
| Log             | double      | double number                                        | The base **e** logarithm of a specified number.                                                                                                                                                                                                                                                                                                                                            |
| Log10           | double      | double number                                        | The base 10 logarithm of a specified number.                                                                                                                                                                                                                                                                                                                                               |
| Max             | double      | double parameters                                    | The maximum from the given list of numbers.                                                                                                                                                                                                                                                                                                                                                |
| Maximum         | double      | InfoObjectCollection collection<br>string columnName | The maximum of all numbers in the specified data column of the objects in the collection.                                                                                                                                                                                                                                                                                                  |
| Min             | double      | double parameters                                    | The minimum from the given list of numbers.                                                                                                                                                                                                                                                                                                                                                |
| Minimum         |             | InfoObjectCollection collection<br>string columnName | The minimum of all numbers in the specified data column of the objects in the collection.                                                                                                                                                                                                                                                                                                  |
| Modulo          | int         | int left<br>int right                                | The modulo of two integer numbers.                                                                                                                                                                                                                                                                                                                                                         |
| Pow             | double      | double base<br>double exp                            | The number raised to the specified power.                                                                                                                                                                                                                                                                                                                                                  |
| Percent         | double      | double percent                                       | Multiples the specified number by 0.01.                                                                                                                                                                                                                                                                                                                                                    |
| Round           | double      | double number<br>_int digits_<br>_string mode_       | The number nearest to the specified value.<br>The optional second parameter sets the number of fractional digits in the rounded value.<br>You can use the third parameter to set the rounding mode for numbers half-way between two other numbers. Supported variants are:<br>AwayFromZero - rounds to the nearest number away from zero<br>ToEven - rounds toward the nearest even number |
| Sign            | double      | double number                                        | Returns a value indicating the sign of a number:<br>-1 (the number is less than zero)<br>0 (the number is zero)<br>1 (the number is greater than zero)                                                                                                                                                                                                                                     |
| Sin             | double      | double number                                        | The sine of the specified angle.                                                                                                                                                                                                                                                                                                                                                           |
| Sinh            | double      | double number                                        | The hyperbolic sine of the specified angle.                                                                                                                                                                                                                                                                                                                                                |
| Sqrt            | double      | double number                                        | The square root of a specified number.                                                                                                                                                                                                                                                                                                                                                     |
| Sum             | double      | InfoObjectCollection collection<br>string columnName | The sum of all numbers in the specified data column of the objects in the collection.                                                                                                                                                                                                                                                                                                      |
| Tan             | double      | double number                                        | The tangent of the specified angle.                                                                                                                                                                                                                                                                                                                                                        |
| Tanh            | double      | double number                                        | The hyperbolic tangent of the specified angle.                                                                                                                                                                                                                                                                                                                                             |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## E-commerce

### General

| Method                    | Return type  | Parameters                                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------- | ------------ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GetManufacturer           | object       | int id<br>string column                        | Returns an object from the specified column (_string column_) of the [manufacturer](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/managing-brands-and-manufacturers.md) with the specified ID (_int id_).                                                                                                                                                                                                                                                                                                                  |
| GetDepartment             | object       | int id<br>string column                        | Returns an object from the specified column (_string column_) of the [department](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/categorizing-products/departments.md) with the specified ID (_int id_).                                                                                                                                                                                                                                                                                                                    |
| GetSupplier               | object       | int id<br>string column                        | Returns an object from the specified column (_string column_) of the [supplier](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/managing-suppliers.md) with the specified ID (_int id_).                                                                                                                                                                                                                                                                                                                                     |
| GetInternalStatus         | object       | int id<br>string column                        | Returns an object from the specified column (_string column_) of the [internal status](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/product-statuses.md) with the specified ID (_int id_).                                                                                                                                                                                                                                                                                                                                |
| GetPublicStatus           | object       | int id<br>string column                        | Returns an object from the specified column (_string column_) of the public status with the specified ID (_int id_).                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| GetCouponsMessage         | string       | object (DiscountInfo) Discount                 | Returns an information message about the redemption count of [coupon codes](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-coupon-codes.md) belonging to the specified [discount](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts.md) (_object Discount_).                                                                                                                                                                                                                  |
| GetMultiBuyCouponsMessage | string       | object (MultiBuyDiscountInfo) MultiBuyDiscount | Returns an information message about the redemption count of [coupon codes](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-coupon-codes.md) belonging to the specified [Buy X Get Y discount](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-buy-x-get-y-discounts.md) or [Product coupon](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-product-coupons.md) (_object MultiBuyDiscount_).                    |
| GetGiftCardCouponsMessage | string       | object (GiftCardInfo) GiftCard                 | Returns an information message containing the total redeemed and remaining amount for all [coupon codes](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-coupon-codes.md) belonging to the specified [Gift card](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/discounts/working-with-gift-cards.md) (_object GiftCard_). The amount values are in the site's [main currency](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-currencies.md). |
| GetFormattedWeight        | string       | double weight                                  | Returns formatted weight (_double weight_) based on the [mass unit format configuration in the settings](https://docs.kentico.com/13/configuring-xperience/managing-sites/configuring-settings-for-sites/settings-e-commerce.md).                                                                                                                                                                                                                                                                                                                             |
| GetMassUnit               | string       |                                                | Returns the [mass unit](https://docs.kentico.com/13/configuring-xperience/managing-sites/configuring-settings-for-sites/settings-e-commerce.md) configured in the settings.                                                                                                                                                                                                                                                                                                                                                                                   |
| GetMainSiteCurrency       | CurrencyInfo | int siteID                                     | Returns the [currency](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-currencies.md) used on the site with the specified ID (_int siteID_).                                                                                                                                                                                                                                                                                                                                                                           |
| FormatPriceForCart        | string       | decimal price<br>int cartID<br>_bool round_    | Returns the price (_decimal price_) formatted according to the [currency](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-currencies.md) used by the specified shopping cart (_int cartID_). The optional parameter determines whether the price is rounded based on the settings of the shopping cart's site (_bool round_).                                                                                                                                                                                          |
| FormatPriceInMainCurrency | string       | decimal price<br>_bool round_                  | Returns the price (_decimal price_) formatted according to the current site's main [currency](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-currencies.md). The optional parameter determines whether the price is rounded based on the current site's settings (_bool round_).                                                                                                                                                                                                                                      |
| IsOptionUsedInVariants    | bool         | int skuId                                      | Returns true if the [product option](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/working-with-product-options.md) with the specified ID (_int skuID_) is used in any existing [product variant](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/working-with-product-variants.md).                                                                                                                                                                                                      |
| ShoppingCartProducts      | IEnumerable  | object (Guid) cartGUID                         | Returns the products (shopping cart items) in the specified shopping cart (_object cartGUID_).<br>Bundle items and product options are not included in the returned collection.                                                                                                                                                                                                                                                                                                                                                                               |

### URLs

| Method                  | Return type | Parameters                                                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ----------------------- | ----------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| GetProductRelativePath  | string      | Guid skuGuid<br>string skuName<br>_string cultureCode_     | Returns the permanent URL for the specified product, as a relative URL path. The product is identified by the GUID (_object skuGuid_) parameter, and the resulting URL includes the specified product name. For example:<br>_\~/getproduct/8c2312c0-b474-45f3-a51b-6b803ed0b1cd/AeroPress?skuculture=en-US_<br>This permanent URL displays the page related to the given product on the live site.<br>Example:<br>_{% Url.MakeAbsolute(GetProductRelativePath(SKUGUID, SKUName), CurrentSite.SiteID) %}_<br>Note: If you wish to generate the standard live site URL of a product page, we recommend using the **Url.GetDocumentRelativePath** method instead.                                                                                                                                                                                                                                                                                                                                                                                                     |
| GetEproductUrl          | string      | Guid fileToken<br>string fileName<br>int siteId            | Returns the URL for downloading an [e-product](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/products/managing-product-representations/managing-e-products.md) specified with a unique download URL (_Guid_  _fileToken_), a file name (_string fileName_), and an ID of the site on which the order with the e-product took place (_int siteId_).<br>Note: E-product URLs generated by this method use the domain and download endpoint of the Xperience administration project. The method cannot be used in scenarios where your administration project is not publicly accessible.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ShoppingCartAbsoluteUrl | string      | string siteName<br>_string cultureCode_<br>_Guid cartGUID_ | Returns the absolute live site URL of the specified site's [shopping cart page](https://docs.kentico.com/13/e-commerce-features/developing-on-line-stores/implementing-a-checkout-process/integrating-the-shopping-cart.md), as configured in **Store configuration** -> **Store settings** -> **General** -> **Shopping cart URL**. For sites that use different presentation [domain aliases for specific cultures](https://docs.kentico.com/13/multilingual-websites/setting-up-multilingual-websites/configuring-urls-for-multilingual-websites.md), you can optionally set the culture.<br>As an optional parameter, you can specify a shopping cart's GUID, which is then added to the URL's query string. The query string value can be processed by the shopping cart page to display the content of the given cart, for example when sending an email reminder about an abandoned shopping cart (this scenario needs to be implemented by the developers of the shopping cart page).<br>Example:<br>_{% ShoppingCartAbsoluteUrl(CurrentSite.SiteName) %}_ |
| WishlistAbsoluteUrl     | string      | string siteName<br>_string cultureCode_                    | Returns the absolute live site URL of the specified site's wishlist page, as configured in **Store configuration** -> **Store settings** -> **General** -> **Wishlist URL**. For sites that use different presentation [domain aliases for specific cultures](https://docs.kentico.com/13/multilingual-websites/setting-up-multilingual-websites/configuring-urls-for-multilingual-websites.md), you can optionally set the culture.<br>Example:<br>_{% WishlistAbsoluteUrl(CurrentSite.SiteName) %}_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## User membership and permissions

| Method                   | Return type | Parameters                                                                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------ | ----------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| CheckPrivilegeLevel      | bool        | object user (UserInfo)<br>UserPrivilegeLevelEnum privilegeLevel           | Checks the user's [privilege level](https://docs.kentico.com/13/managing-users/user-management.md). Returns a true value if the user's privilege level matches the required _UserPrivilegeLevelEnum_ value or is higher.<br>You can check the following levels:<br>_{% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor) %}_<br>_{% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) %}_<br>_{% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) %}_                                                                        |
| GetFormattedUserName     | string      | object user (UserInfo)<br>_bool isLiveSite_                               | Returns the formatted username of the specified user object. The default format is&#x20;_&#x20;()_ if the user has a nickname, otherwise&#x20;_&#x20;()_.<br>The **isLiveSite** parameter determines whether the macro displays the username on the live website.                                                                                                                                                                                                                                                                                                        |
| HasAnyMembership         | bool        | object user (UserInfo)                                                    | Checks whether the user belongs to any [membership](https://docs.kentico.com/13/managing-users/membership-management.md) in the system.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| HasMembership            | bool        | object user (UserInfo)<br>string userMemberships<br>_bool allMemberships_ | Checks if a user belongs to the specified [memberships](https://docs.kentico.com/13/managing-users/membership-management.md).<br>Enter the code names of memberships through the **userMemberships** parameter. When checking multiple memberships, use semicolons (;) to separate the code names. If the **allMemberships** parameter is true, the user must belong to all specified memberships for the check to succeed.<br>To check whether the user belongs to a membership on a global level, add the period character (.) prefix before the membership code name. |
| IsAuthorizedPerResource  | bool        | object user (UserInfo)<br>string resource<br>string permission            | Evaluates whether a user has a specific [permission](https://docs.kentico.com/13/managing-users/configuring-permissions.md) for a resource (module). Use code names to identify the resource and permission.                                                                                                                                                                                                                                                                                                                                                             |
| IsAuthorizedPerUIElement | bool        | object user (UserInfo)<br>string resource<br>string elementName           | Evaluates whether a user is allowed to access a specific UI element of a resource (module). Use code names to identify the resource and element.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| IsInRole                 | bool        | object user (UserInfo)<br>string userRole<br>_bool allRoles_              | Checks if a user belongs to the specified roles.<br>Enter the code names of roles through the **userRole** parameter. When checking multiple roles, use semicolons (;) to separate the code names. If the **allRoles** parameter is true, the user must belong to all specified roles for the check to succeed.<br>To check whether the user belongs to a role on a global level, add the period character (.) prefix before the role code name.                                                                                                                         |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)

## Transformations

| Method              | Return type | Parameters                                                                                                                                 | Description                                                                                                                                                                                                                                                                                        |
| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ApplyTransformation | string      | IEnumerable collection<br>string transformationName<br>_string contentBeforeTransformationName_<br>_string contentAfterTransformationName_ | Applies [transformations](https://docs.kentico.com/13/macro-expressions/writing-transformations-for-macros.md) to a collection of items or a single object.                                                                                                                                        |
| Transform           | string      | IEnumerable collection<br>string transformationText                                                                                        | Applies ad-hoc transformation code to a collection of items or a single object.<br>Note: To keep the macro syntax valid, you need to break all _%}_ closing macro tags within the ad-hoc transformation code into separate strings.<br>Example: _{% CurrentUser.Transform("{%FullName%" + "}") %}_ |

[> Back to the list of macro method categories](#referencemacromethods-macromethodstop)
