Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Kentico: using a boolean custom setting in a macro

Modified: 2014/04/25 17:11 by vanthoog - Categorized as: Kentico
The following applies to Kentico v7.0. It probably also applies to previous versions, although this has not been tested.

Within macros you can use advanced expressions written in the K# language. Suppose you have added a custom settings called “UseMobileFrontend”, defined as a boolean, and you want to use this in an if-statement in a macro. At first you might expect that the following would work:

{%if (Settings.CustomSettings.General.UseMobileFrontend) {"some text"} #%}

But unfortunately this does not work. To make this work you have to use the conversion method ToBool:

{%if (ToBool(Settings.CustomSettings.General.UseMobileFrontend)) {"some text"} #%}

The method ToBool has an optional second parameter defining a default value which will be used if the supplied first parameter cannot be converted into a boolean.

 © Evident Interactive BV