Skip to main content
MindTouch Success Center

Apply conditional global variables (MT4)

Written by Damien Howley
Former MindTouch Employee at MindTouch
This page applies to:MindTouch 4

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. 

Why would I need to have 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.  

What are global variables and how are they used?

Global variables are values that are defined in one central interface and are accessible throughout your entire collection of documentation.  They are used in situations where you have a common term or name that is used frequently and may change over time.  

For example, you may have a global variable for your product Version Number that is included in 1,000 different articles.  When your company releases a new product version, you may be tasked with updating all 1,000 references to the version number.  If you use global variables, you will only have to update the version number in one place.  

Defining the global variable in /Template:System/Variables

let export = {
    productname : "Mosarch",  
    productversion : "7.13"

Using the variable in your MindTouch pages

Here is my regular text. Here is my text about {{productname}}, specifically I am talking about
version {{productversion}}

How do I condition global variables?

You can update your global variables by going to Site Tools > Templates > System Variables or by going to Template:System/Variables.  It is important that you first declare the variable in the standard export variable before you re-declare it through 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";
    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 structure framework makes setting up your structure easy.  Once your structure is setup, you may want to have 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"
  • Was this article helpful?