Skip to main content

Conditionalize sections of an article (TCS)

This article reviews how to set up an article to display content conditionally depending on who is reading the article. 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.

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 administrative privileges. This means that if you exclude content from being shown to an anonymous user, 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 provides the correct direction for search, and once users navigate to the page, they will see additional information that pertains to them.

Conditionalize content within Editor

  1. Find the tool called Formatting Styles and click on it.​


  1. When the drop down menu pops up observe the options called "Conditional Text (Anonymous Only)", "Conditional Text (Community-Members Only)", and "Conditional Text (Pro-Members Only)".       


  1. If you click on any of these and enter text within them, only users that fall under that category will be able to view the content.


  1. Click Save.



As you can see in this example, I am signed in as a pro member so I can see only the pro-member comment.


Remove 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.

Set 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 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.  

Set up 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".  

Set 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:

editor settings.png

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:

conditional format.png


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. 

Add 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>
  • Was this article helpful?