Reference - Macro methods

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

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
  • string column
  • 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.

Example:

{% Documents[“/Articles”].GetValue(“Title”) %}

GetProperty

object

  • IHierarchicalObject object
  • string property
  • 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.

Example:

{% Documents[“/Articles”].GetProperty(“Title”) %}

GetItem

object

  • IEnumerable collection
  • int index
  • 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.

Example:

{% GlobalObjects.Users.GetItem(0).UserName %}

OrderBy

IInfoObjectCollection

  • IInfoObjectCollection collection
  • string orderBy

Returns the collection of objects, with the order defined by the specified SQL ORDER BY clause.

If the macro is saved by a user without the Administrator privilege level, the method only allows the following SQL syntax:

  • one or more column names (separated by commas)
  • the ASC and DESC keywords

Example:

{% GlobalObjects.Users.OrderBy(“UserCreated DESC”).FirstItem.UserName %}

Where

IInfoObjectCollection

  • IInfoObjectCollection collection
  • string where

Filters a collection of objects according to the specified SQL Where condition.

If the macro is saved by a user without the Administrator privilege level, the method only allows the following SQL syntax in the where condition:

  • column names, values and basic operators: =, !=, >, <
  • AND & OR operators, parentheses
  • column BETWEEN value AND value
  • column LIKE value
  • column IN (values)
  • column IS NULL
  • NOT keyword for the above expressions (NOT BETWEEN, NOT LIKE, NOT IN, IS NOT NULL)

Other expressions and SQL functions are not supported.

Example:

{% GlobalObjects.Users.Where(“Email LIKE ‘%@localhost.local’”).FirstItem.UserName %}

TopN

IInfoObjectCollection

  • IInfoObjectCollection collection
  • int topn

Returns only the specified number of objects in the collection.

Example:

{% GlobalObjects.Users.TopN(1).FirstItem.UserName %}

Columns

IInfoObjectCollection

  • IInfoObjectCollection collection
  • string columns

Returns the collection of objects containing only the specified data columns.

If the macro is saved by a user without the Administrator privilege level, the method only allows the following SQL syntax:

  • one or more column names (separated by commas)
  • SQL aliases for columns defined using the AS keyword (must be upper case)

Example:

{% GlobalObjects.Users.Columns(“UserName, Email”).FirstItem.UserName %}

Filter

IList

  • IEnumerable collection
  • MacroExpression condition

Filters a collection of objects according to the specified macro condition.

Example:

{% GlobalObjects.Users.Filter(UserID == 53).FirstItem.UserName %}

ClassNames

TreeNodeCollection

  • TreeNodeCollection collection
  • string classNames

Filters a TreeNodeCollection of pages according to the specified page types. The second parameter must contain a list of allowed page type code names, separated by semicolons.

Example:

{% Documents.ClassNames(“site.article;site.news”).Count %}

InList

bool

  • object object
  • IEnumerable collection

Returns a true value if the object exists within the specified collection.

Example:

{% Documents[“/Articles”].ClassName.InList(“site.article,cms.root”.Split(“,”)) %}

All

bool

  • IEnumerable collection
  • 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.

Example:

{% GlobalObjects.Users.All(UserEnabled == true) %}

Any

bool

  • IEnumerable collection
  • 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.

If you leave out the condition parameter, the method returns true if the collection contains at least one object.

Throws an exception if the collection is null.

Example:

{% GlobalObjects.Users.Any(UserEnabled == false) %}

Exists

bool

  • IEnumerable collection
  • 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.

If you leave out the condition parameter, the method returns true if the collection contains at least one object.

Returns false if the collection is null.

Example: {% GlobalObjects.Users.Exists(UserEnabled == false) %}

RandomSelection

IList

  • IEnumerable items
  • int numberOfItems

Returns randomly selected objects from the collection. You can optionally specify the number of items.

Example:

{% GlobalObjects.Users.RandomSelection().UserName %}

SelectInterval

IList

  • IEnumerable items
  • int lowerBound
  • int upperBound

Returns the specified interval of objects from the collection.

Example:

{% Documents.SelectInterval(0,9) %}

Cache

object

  • object expression
  • int cacheMinutes
  • bool condition
  • string cacheItemName
  • string cacheItemNameParts
  • 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.

See also: Caching the results of macros

GetCacheDependency

CMSCacheDependency

  • string[] dependencies

Returns a CMSCacheDependency object based on the specified dummy cache keys (one or more string parameters).

See also:

> Back to the list of macro method categories

Data conversion

Method

Return type

Parameters

Description

ToString

string

  • object value
  • string defaultValue
  • string culture
  • string format

Converts an object to a string. Returns the optional default value if the conversion is not possible.

You can also specify the culture context and a formatting string used for the conversion.

Examples:

  • {% DocumentName.ToString() %}
  • {% DocumentName.ToString(“defaultValue”) %}
  • {% DocumentName.ToString(“defaultValue”, “en-US”) %}
  • {% DocumentName.ToString(“defaultValue”, DocumentCulture, “Document name is: {0}”) %}

ToInt

int

  • object value
  • int defaultValue

Converts an object to an integer number. Returns the optional default value if the conversion is not possible.

Example: {% DocumentID.ToInt() %}

ToBool

bool

  • object value
  • bool defaultValue

Converts an object to a boolean value. Returns the optional default value if the conversion is not possible.

Example: {% DocumentShowInSiteMap.ToBool() %}

ToDecimal

decimal

  • object value
  • decimal defaultValue
  • string culture

Converts an object to a decimal number. Returns the optional default value if the conversion is not possible.

You can also specify a culture code to determine the formatting of the decimal number.

Examples:

  • {% DocumentID.ToDecimal() %}
  • {% DocumentID.ToDecimal(“0.0”, DocumentCulture) %}

ToDouble

double

  • object value
  • double defaultValue
  • string culture

Converts an object to a double number. Returns the optional default value if the conversion is not possible.

You can also specify a culture code to determine the formatting of the double number.

Examples:

  • {% DocumentID.ToDouble() %}
  • {% DocumentID.ToDouble(“0.0”, DocumentCulture) %}

ToGuid

guid

  • object value
  • Guid defaultValue

Converts an object to a GUID value. Returns the optional default value if the conversion is not possible.

Example: {% DocumentGUID.ToGuid() %}

ToDateTime

DateTime

  • object value
  • DateTime defaultValue
  • string culture

Converts an object to a DateTime value. Returns the optional default value if the conversion is not possible.

You can also specify a culture code to determine the date format.

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.

Example: {% FromOADate(43100.999305556) %}

ToTimeSpan

TimeSpan

  • object value

Converts an object to a TimeSpan value. Returns null if the conversion is not possible.

Example: {% ToTimeSpan(“1:00:00”) %}

ToBaseInfo

BaseInfo

  • object value
  • 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.

Example: {% CurrentUser.ToBaseInfo() %}

List

ArrayList

  • object items

Converts a list of objects to an ArrayList.

Example: {% List(“Apple”, “Orange”, “Banana”) %}

> Back to the list of macro method categories

Text manipulation

Method

Return type

Parameters

Description

Contains

bool

  • string text
  • string search

Returns a true value if the string specified by the second parameter occurs within the first string.

EndsWith

bool

  • string text
  • string findText

Indicates whether the string specified by the second parameter occurs at the end of the first string.

EnsureMaximumLineLength

string

  • object textObj
  • 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.

The method does not support text containing HTML tags.

Format

string

  • string value
  • string format

Replaces all formatting expressions in a string using the text equivalents specified in the second parameter.

Based on composite formatting.

FormatNotEmpty

string

  • string value
  • string format
  • 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.

Based on composite formatting.

GetEmailDomain

string

  • string email

Returns the domain segment from the specified email address value.

GetMatch

string

  • string text
  • string regex

Matches the string value to the specified regular expression and returns the match.

IndexOf

int

  • string text
  • string searchFor

Returns the index of the first occurrence of the second string within the first string.

LastIndexOf

int

  • string text
  • string searchFor

Returns the index of the last occurrence of the second string within the first string.

LimitLength

string

  • string text
  • int length
  • string padString
  • bool wholeWords

Limits the length of the string to the specified number of characters.

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.

If you set the wholeWords parameter to true, the method preserves the last word in the string.

LoremIpsum

string

  • int length

Generates lorem Ipsum text. You can specify the number of generated characters (1000 by default).

Matches

bool

  • string text
  • string regex

Indicates whether the string matches the specified regular expression.

NotContains

bool

  • string text
  • 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
  • int length
  • string paddingString

Adds leading characters to the string until the total length matches the second parameter.

By default, the method uses spaces as the padding character, but you can optionally specify a different character.

PadRight

string

  • string text
  • int length
  • string paddingString

Adds trailing characters to the string until the total length matches the second parameter.

By default, the method uses spaces as the padding character, but you can optionally specify a different character.

RegexReplace

string

  • string text
  • string regex
  • string replacement

Replaces strings that match the regular expression pattern within the first string using the replacement string.

Remove

string

  • string text
  • int position
  • 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
  • string replace
  • string replacement

Replaces all occurrences of the second string within the first string using the replacement string.

Split

string[]

  • string text
  • string delimiters
  • 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
  • string findText

Indicates whether the string specified by the second parameter occurs at the start of the first string.

Substring

string

  • string text
  • int index
  • 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
  • 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
  • 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
  • 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).

Tips: To perform lexicographical comparison of strings, use the basic comparison operators (==, <, >, <=, >=).  Add macro parameters to specify case sensitivity and the culture context of text operations.

> Back to the list of macro method categories

Advanced text processing

Method

Return type

Parameters

Description

GetResourceString

string

  • string resourceStringKey
  • string culture

Translates the specified resource (localization) string. 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:

{% HTMLEncode(“Sample text <br />”) %}

JSEscape

string

  • string text

Escapes the string for safe usage in JavaScript. Adds the \ escape character before special characters used by JavaScript (quotes, etc.).

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
  • string culture

Resolves localization expressions 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:

{% 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.

Does not remove HTML Entities, 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

Page and file URLs

Method

Return type

Parameters

Description

GetMediaFileDirectPath

string

  • int libraryId
  • string filePath

Returns the direct URL to the specified media library file on the file system, as a relative URL path. For example:

~/MySite/media/CoffeeGallery/sample_image.jpg

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).

The method does NOT check the permissions of users to view the given file.

Example:

{% GetMediaFileDirectPath(FileLibraryID, FilePath) %}

GetMediaFileRelativePath

string

  • Guid fileGUID
  • string fileName

Returns the permanent URL for the specified media library file, 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:

~/getmedia/9707c8ff-cd3d-4045-b697-a7d012093cd6/sampleImage

The method evaluates the permissions of the current user to view the given file.

Example:

{% 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
  • string attachmentFileName
  • 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 and unsorted attachments. You can optionally generate a URL for an image variant of the attachment by specifying an image variant definition identifier.

Note: The method must always be called from the Url macro namespace, using prefix notation.

Example:

{% 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).
Note: The method must always be called from the Url macro namespace, using prefix notation.

Example:

{% Url.GetDocumentRelativePath(Documents[“/Articles”].DocumentID) %}

Url.MakeAbsolute

string

  • string relativeUrl
  • int siteId
  • 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, you can optionally set the culture.

Note: The method must always be called from the Url macro namespace, using prefix notation.

Examples:

{% Url.MakeAbsolute(GetMediaFileDirectPath(FileLibraryID, FilePath), CurrentSite.SiteID) %}

{% Url.MakeAbsolute(Url.GetDocumentRelativePath(Documents[“/Articles”].DocumentID), CurrentSite.SiteID) %}

> Back to the list of macro method categories

Date and time

Method

Return type

Parameters

Description

AddMilliseconds

DateTime

  • DateTime datetime
  • int milliseconds

Adds the specified number of milliseconds to a DateTime value.

AddSeconds

DateTime

  • DateTime datetime
  • int seconds

Adds the specified number of seconds to a DateTime value.

AddMinutes

DateTime

  • DateTime datetime
  • int minutes

Adds the specified number of minutes to a DateTime value.

AddHours

DateTime

  • DateTime datetime
  • int hours

Adds the specified number of hours to a DateTime value.

AddDays

DateTime

  • DateTime datetime
  • int days

Adds the specified number of days to a DateTime value.

AddWeeks

DateTime

  • DateTime datetime
  • int weeks

Adds the specified number of weeks to a DateTime value.

AddMonths

DateTime

  • DateTime datetime
  • int months

Adds the specified number of months to a DateTime value.

AddYears

DateTime

  • DateTime datetime
  • 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.

For example:

{% FormatDate(DateTime.Now) %}

FormatDateTime

string

  • DateTime dateTime
  • string format

Displays the date and time value according to a format string. The method formats the date and time according to the current culture context.

For example:

{% FormatDateTime(DateTime.Now, “MM/dd/yyyy HH:mm”) %}

GetCustomDateTime

DateTime

  • DateTime dateTime
  • string timeZoneName

Converts a date and time value to a specific time zone (identified by the time zone code name).

For example:

{% GetCustomDateTime(DateTime.Now, “GreenwichMeanTime”) %}

GetSiteDateTime

DateTime

  • DateTime dateTime

Converts the specified date and time value to the current site’s time zone.

GetUserDateTime

DateTime

  • DateTime dateTime

Converts the specified date and time value to the time zone 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

Mathematical operations

The macro autocomplete help 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
  • 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
  • int maxValue
  • 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
  • int maxValue
  • 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
  • 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
  • string columnName

The minimum of all numbers in the specified data column of the objects in the collection.

Modulo

int

  • int left
  • int right

The modulo of two integer numbers.

Pow

double

  • double base
  • double exp

The number raised to the specified power.

Percent

double

  • double percent

Multiples the specified number by 0.01.

Round

double

  • double number
  • int digits
  • string mode

The number nearest to the specified value.

The optional second parameter sets the number of fractional digits in the rounded value.

You can use the third parameter to set the rounding mode for numbers half-way between two other numbers. Supported variants are:

  • AwayFromZero - rounds to the nearest number away from zero
  • ToEven - rounds toward the nearest even number

Sign

double

  • double number

Returns a value indicating the sign of a number:

  • -1 (the number is less than zero)
  • 0 (the number is zero)
  • 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
  • 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

E-commerce

General

Method

Return type

Parameters

Description

GetManufacturer

object

  • int id
  • string column

Returns an object from the specified column (string column) of the manufacturer with the specified ID (int id).

GetDepartment

object

  • int id
  • string column

Returns an object from the specified column (string column) of the department with the specified ID (int id).

GetSupplier

object

  • int id
  • string column

Returns an object from the specified column (string column) of the supplier with the specified ID (int id).

GetInternalStatus

object

  • int id
  • string column

Returns an object from the specified column (string column) of the internal status with the specified ID (int id).

GetPublicStatus

object

  • int id
  • 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 belonging to the specified discount (object Discount).

GetMultiBuyCouponsMessage

string

  • object (MultiBuyDiscountInfo) MultiBuyDiscount

Returns an information message about the redemption count of coupon codes belonging to the specified Buy X Get Y discount or Product coupon (object MultiBuyDiscount).

GetGiftCardCouponsMessage

string

  • object (GiftCardInfo) GiftCard

Returns an information message containing the total redeemed and remaining amount for all coupon codes belonging to the specified Gift card (object GiftCard). The amount values are in the site’s main currency.

GetFormattedWeight

string

  • double weight

Returns formatted weight (double weight) based on the mass unit format configuration in the settings.

GetMassUnit

string

Returns the mass unit configured in the settings.

GetMainSiteCurrency

CurrencyInfo

  • int siteID

Returns the currency used on the site with the specified ID (int siteID).

FormatPriceForCart

string

  • decimal price
  • int cartID
  • bool round

Returns the price (decimal price) formatted according to the currency 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
  • bool round

Returns the price (decimal price) formatted according to the current site’s main currency. 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 with the specified ID (int skuID) is used in any existing product variant.

ShoppingCartProducts

IEnumerable
<ShoppingCartItemInfo>

  • object (Guid) cartGUID

Returns the products (shopping cart items) in the specified shopping cart (object cartGUID).

Bundle items and product options are not included in the returned collection.

URLs

Method

Return type

Parameters

Description

GetProductRelativePath

string

  • Guid skuGuid
  • string skuName
  • 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:

~/getproduct/8c2312c0-b474-45f3-a51b-6b803ed0b1cd/AeroPress?skuculture=en-US

This permanent URL displays the page related to the given product on the live site.

Example:

{% Url.MakeAbsolute(GetProductRelativePath(SKUGUID, SKUName), CurrentSite.SiteID) %}

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
  • string fileName
  • int siteId

Returns the URL for downloading an e-product 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).

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
  • string cultureCode
  • Guid cartGUID

Returns the absolute live site URL of the specified site’s shopping cart page, as configured in Store configuration -> Store settings -> General -> Shopping cart URL. For sites that use different presentation domain aliases for specific cultures, you can optionally set the culture.

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).

Example:

{% ShoppingCartAbsoluteUrl(CurrentSite.SiteName) %}

WishlistAbsoluteUrl

string

  • string siteName
  • 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, you can optionally set the culture.

Example:

{% WishlistAbsoluteUrl(CurrentSite.SiteName) %}

User membership and permissions

Method

Return type

Parameters

Description

CheckPrivilegeLevel

bool

  • object user (UserInfo)
  • UserPrivilegeLevelEnum privilegeLevel

Checks the user’s privilege level. Returns a true value if the user’s privilege level matches the required UserPrivilegeLevelEnum value or is higher.

You can check the following levels:

  • {% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor) %}
  • {% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) %}
  • {% CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) %}

GetFormattedUserName

string

  • object user (UserInfo)
  • bool isLiveSite

Returns the formatted username of the specified user object. The default format is <full name> (<nickname>) if the user has a nickname, otherwise <full name> (<username>).

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 in the system.

HasMembership

bool

  • object user (UserInfo)
  • string userMemberships
  • bool allMemberships

Checks if a user belongs to the specified memberships.

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.

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)
  • string resource
  • string permission

Evaluates whether a user has a specific permission for a resource (module). Use code names to identify the resource and permission.

IsAuthorizedPerUIElement

bool

  • object user (UserInfo)
  • string resource
  • 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)
  • string userRole
  • bool allRoles

Checks if a user belongs to the specified roles.

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.

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

Transformations

Method

Return type

Parameters

Description

ApplyTransformation

string

  • IEnumerable collection
  • string transformationName
  • string contentBeforeTransformationName
  • string contentAfterTransformationName

Applies transformations to a collection of items or a single object.

Transform

string

  • IEnumerable collection
  • string transformationText

Applies ad-hoc transformation code to a collection of items or a single object.

Note: To keep the macro syntax valid, you need to break all %} closing macro tags within the ad-hoc transformation code into separate strings.

Example: {% CurrentUser.Transform(“<strong>{%FullName%” + “}</strong>”) %}

> Back to the list of macro method categories