Blog

On this page you will find Tutorials, How-Tos and Tips for developing with open bi.

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:

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.

Expression
Documentation
Expression
@ViewBag.Cms.OpenBiRequest.Handle
Documentation
The current session handle
Expression
@ViewBag.Cms.OpenBiRequest.User?.Username
Documentation
The username of the current user or null.
Expression
@ViewBag.Cms.Page.Title
Documentation
The title of the current page
Expression
@ViewBag.Translate("language text")
Documentation
The text of the language text for the current language
Expression
@ViewBag.Cms.Organisation.Name
Documentation
The name of the organization

Thilo Knötzele
Author: Thilo Knötzele
Creation date: 06.07.2021
Category: Web Development
back to overview