Protiviti / SharePoint Blog

SharePoint Blog

September 07
Kentico Macros in Page Types, Web Parts, and Widgets

Macros in Kentico are text shortcuts that are used to evaluate and display data.  They are extremely flexible and can display server context, user context, query string parameters, and even process complex logic such as code blocks or call into Kentico’s .Net API.  There is a catch however when using macros with page types, web parts, and widgets.

If a macro is used to populate a default value for a field then that field cannot be displayed on the edit form for the respective component.  I have read this is a security issue from Kentico’s standpoint but it really behaves more like a bug.  When displayed on an edit form the last component edited and saved containing a macro for a default value will save that value into all components using that field (matched by GUID).  What this means is if we have 3 pages A, B, and C that share a common page type and we choose to add a macro that takes the current user’s identity and stores it on the page (via default field value) if we edit page B then save it the value resolved in page B will automatically show for pages A and C even if we do not modify the value.  This is a problem because we added the macro to the default value of the field at the Page Type level, not any specific page.  

The solution to this problem is to go to the Fields section of the page type, web part, or widget, select the field where we have our default value set to the macro, then uncheck the box labeled Display field in the editing form.  This fixes the issue and now we have dynamic rendering of the macro for every page, web part, or widget using the field.

Details on macros can be found here:

Quick Launch

© Protiviti 2020. All rights reserved.   |   Privacy Policy