Skip to main content

Create conditional content on a page (TCS)


This article reviews how to set up an article to display content conditionally depending on who is reading the article.

Use Case

There are multiple scenarios where you want to conditionalize the content within your documentation so that depending on the user reading the article, they will receive a different experience and see different information that will pertain to them.


After completing this tutorial you will be able to add conditional content within any article in your MindTouch site.

Conditional Content in the Product

MindTouch ships with three default Conditional Content Blocks. These are pro members, community members, and anonymous members. You can also create your own Conditional Content Blocks and add any user you want to those groups. The following explains how to create a customized Conditional Content Block. 

Setting up Conditional Content

Before we get started with implementation, identify the users that you want to segment out within your content.  For the sake of this tutorial we will have 2 user groups.  One group will be Editors and the other group will be Administrators

Create the groups

Now that we have identified our groups, we can login to the Control Panel within MindTouch and create these two groups and put the users in them.  If you need help setting up the groups, check out our Group Management documentation.  We are calling our groups: Editors and Administrators

Note that if these groups are already setup in your system or being synchronized from an external authentication provider, then you don't have to recreate them.  

Setup the Conditional classes

This section will require some DekiScripting. Below are examples that will give you a starting point.  Create a new page and click on View -> Source.  Once in source view, we're going to add the following source:


<div if="user.groups['Administrators']">Sample</div>

This is a conditional statement that checks if the person that is accessing this article is in the Administrators group. If they are, then we show them the word "Sample".  


Setting up the Conditional classes for reuse

Once you have tested the above code with the groups you have set up, you can take this one step further and make it easy for your authors to insert a conditional block.  To do so follow these steps:

  1. Copy the div statement minus the sample text
  2. Go into the Control Panel -> Editor
  3. Add the following block of code into the Set Editor Configuration text area:


CKEDITOR.editorConfig = function( config )
config.stylesSet.push({ name : 'Administrators Conditional Block', element : 'div', wrap:true, attributes : { 'if' : 'user.groups["Administrators"]'} });

Above you'll see a couple of highlighted items.  Here is how you will replace them with your div code:


  • Administrators Conditional Block = Provide a name that will be easy for your authors to understand and select so they know the user base that the condition applies to
  • user.groups["Administrators"]  = Replace this with the conditional block that you want to use


Once added to the editor settings it will look like this:


If everything looks good, then click Save Changes.  Now go to the front end of MindTouch and edit a page.  If you click on the formatted drop down you'll see the following:



You can add as many Conditional blocks as you want.  When you select the block, it will insert it, but it may be hard to see where the block starts and ends.  If you select View -> Show Blocks this will show the boundaries of the block itself.  To exit out of a block click SHIFT + ENTER.


Once the blocks are setup, your authors can add these into any articles and have content conditionally display based upon the user's group membership.

Removing Conditional Content

To turn a conditional content region back to regular content:

  1. Highlight the conditional content region
  2. Open the Formatting Styles menu
  3. Click the conditional content style that is currently highlighted

Conditional content is toggled similar to formats like bold and italic, and applying it twice restores the content to the original state.

Adding more than one group to a statement

From time to time, there will be a need for more than one group to be able to see the same content. With our Conditional Content statements, this has become even easier.



By adding the 'OR' parameter within your statement, members of the Administrators Group or the Editors Group will be able to see the content within that specific statement.

When adding the 'OR' parameter within your statement,  double straight bars are needed as seen in the example below:

<div if="user.groups['Administrators'] || user.groups['Editors']">Sample</div>



By adding the 'AND' parameter within your statement, members of the Administrators Group and the Editors Group will be able to see the content within that specific statement.

When adding the 'AND' parameter within your statement,  double ampersands are needed as seen in the example below:

<div if="user.groups['Administrators'] && user.groups['Editors']">Sample</div>


The 'NOT'  parameter is also available.  A single exclamation point will check if a user is not part of the group:

<div if="!user.groups['Administrators']">Sample</div>

Notes on implementation

Using conditional content within a page is a great way to personalize the experience for your users. The search engine will only find conditional content if you allow anonymous users access to the content. When the MindTouch search engine indexes articles within your site, it does so as an anonymous user with Admin privileges. This means that if you exclude content from being shown to an anonymous user looking at the article, that conditional content will not be indexed by the search engine. If you allow an anonymous user to see the content, it will be indexed by the search engine. Note that in most cases the content that is shown to everyone will provide the correct direction for search, and once the user navigates to the page they will see additional information that pertains to them.

What's Next

Try out more of our DekiScript tutorials to increase the use of your MindTouch site.