Skip to main content
MindTouch Success Center

Use global variables to conditionalize content

Written by Damien Howley
Former MindTouch Employee at MindTouch
This page applies to:MindTouch (current)

This article demonstrates how to apply numerous page and user conditions to your existing global variables.  This material is particularly valuable for users who copy large quantities of content for translation or versioning. 
 

Prerequisite


Why should I set up conditional global variables?


Global variables already provide you with a quick and easy way to manage your documentation vocabulary across large quantities of content.  Conditional global variables provide an extra layer of flexibility and control to your global variables by giving you the ability to personalize their value based on the page they're on or the user that is viewing them.
 

How to declare your conditions


  1. Navigate to Site tool > Dashboard > Content management > Global variables.
  2. Open the Variables page in Edit mode.
  3. Declare the condition as appropriate (see examples below)
     

You must first declare the variable in the standard export variable before you re-declare it through conditions. 

 

Examples of conditions


Condition Description Example
User group

You can use different user groups to control the conditional global variables for users.  For instance, different customer levels may have terms for the features or functions.  Example:

  • Standard = Mosarch
  • Premium = Mosarch+
  • Enterprise = Mosarch Pro
if (user.groups["enterprise"]) {
    export.productname = "Mosarch Pro";
};
User role In MindTouch, we have numerous user roles that are used to control the level of engagement of your users. Typically, your customers are community members, and your colleagues are authors, editors, and administrators.  Authors, editors and administrators are all pro members and are considered "seated" users. Each uses one of your user licenses. You can condition terms based on whether users are seated or unseated.
if (user.unseated) {
    export.feature = "Super Search";
}
else
{
    export.feature = "search v4.2";
}
Page path When you create your content in MindTouch, it is crucial that you create your content using a hierarchy that is intuitive and navigable.  The MindTouch content framework makes setting up your structure easy. Once your structure is set up, you may want to use global variables that vary based on where your user is in the hierarchy.  
var pg = string.split(page.path,"/");
var root = pg[0];

if (root == "Beta") {
    export.version = "4.9 beta"
};