Popular Kentico Macros

Kentico provides an object-oriented language named K#, which defines the syntax of Macro expressions. The Macro language is similar to the C# programming language.

Display Page Title

{% CurrentDocument.DocumentName@ %}

Display Current Document Name

{% CurrentPageInfo.DocumentName #%}

Display Current Document Meta Description

{% StripTags(MenuItemSummary) %}

Display Current Document Absolute URL

{% CurrentDocument.AbsoluteURL #%}

Display Search Query String Parameter

{% QueryString["searchtext"] %}

Display attachments from the Document attachments field

{% foreach (attachment in Documents[NodeALiasPath].AllAttachments) {
"<a href='/getattachment/" + attachment.AttachmentGUID + "/attachment.aspx'>" + attachment.AttachmentName + "</a><hr />";
} %}

Also, to display one document attachment

<a href="/getattachment/{% Object.AllAttachments.GUIDs %}/attachment.aspx" target="_blank">{% Object.AllAttachments.DisplayNames %}</a>

Display Authenticated user name

{% if (MembershipContext.AuthenticatedUser){ %}
Welcome {% MembershipContext.AuthenticatedUser.DisplayName %}
{% }else{ %}
Please log in
{% } %}

Display list of categories assigned to a page

{% Object.Categories.OrderBy("CategoryParentID").Transform("{#DisplayName#}({#CategoryParent#}), ") #%}

Display list of categories assigned to a page based on parent category ID (hardcoded ID)

{% Object.Categories.Where("CategoryParentID=20").Transform("{#DisplayName#}, ") %}

See more Macro Syntax examples.