Using Conditions in the CMS
This blog post shows you one of the advanced functions of CMS on open bi.
If you have the requirement for your web project to show information or content conditionally, you have two options with open bi:
- implementing an HTML item
- writing Razor expressions in the HTML outline.
For sure the latter option is the simplest way to add conditions, as you do not have to bother about all specialities of HTML items. There will be separate tutorials on how to create custom HTML items.
The CMS uses a custom version of Razor which provides basic C# features inside the HTML. These are for example:
- if else conditions
- for, while, do and foreach loops
- access to some CMS related properties
One important thing to note is that Razor uses the "@" symbol as keyword, which means that every normal "@" sign must be escaped with another "@" symbol (example: "@@").
Examples
Using properties in Javascript:
string template = "Hello @ViewBag.Cms.OpenBiRequest.User?.Username, welcome to open bi CMS!";
Using properties in the HTML markup:
@* Corporate Admin *@
@if (ViewBag.Cms.OpenBiRequest.User.RuntimeUserGroups.ContainsKey("2fddd0c5-2a7b-40be-b742-0778fee9e046")) {
<span>Corporate Admin</span>
} else {
<span>No Corporate Admin</span>
}
CMS releated expressions
The following list shows some examples for CMS related expressions. In general you can access all fields of the open bi API in conditions.