Skip to main content
MindTouch Success Center

Create custom conditional content groups

Applies to:
All MindTouch Versions
Role required:
Create conditional content blocks to display sections of text to specified users only.

Why create custom conditional groups?

By default MindTouch ships with three conditional content blocks (pro member, community member and anonymous member content blocks). These content blocks allow you to display text to only users that belong to these groups. By creating custom conditional content groups, you can further segment users into groups that are to access information you don't want to share with all types of users: 

  • You need to include technical notes in a page for your support team but don't want the public to see those notes.
  • Authors and editors add information to a page that has yet to go through a vetting process.
  • Your pro users are contractually entitled to certain information while other users are not. 

Implementation of conditional content for specific groups requires some coding experience. Keep in mind that while conditional content will be displayed to the respective users, this content is not searchable within MindTouch.

Create your custom conditional content blocks

Create groups

  1. Identify your user groups. Before you get started with implementation, identify the users you want to segment out by groups. For the sake of this tutorial, we will create two user groups: the Editors group and the Administrators group. 
  2. Create your user groups. In our case, we called them Editors and Administrators.

If these groups are already set up in your system or are being synchronized from an external authentication provider, don't recreate them.  

Set up conditional classes

The conditional statement below checks if the user accessing this article is part of the Administrators group. If the user is, they will be able to see the word "Sample":

  1. Create a new page.
  2. Click on View > Source.
  3. In Source view,  add the following:
<div if="user.groups['Administrators']">Sample</div>
  1. Repeat steps 1 through 3 for any each of your groups by replacing Administrators in the code above with the name of your groups.
  2. Test the code with the groups you have setup.

Create conditional content blocks

  1. Navigate to Control panel > System SettingsEditor.
  2. Copy the following code into the Set editor configuration text field:
CKEDITOR.editorConfig = function( config )
config.stylesSet.push({ name : 'Administrators Conditional Block', element : 'div', wrap:true, attributes : { 'class' : 'mt-style-conditional', 'if' : 'user.groups["Administrators"]'} });
  1. Replace the following:
  • Administrators Conditional Block = replace with an easily recognizable name for the user group your authors will apply conditional text to
  • user.groups["Administrators"]  = replace with the conditional block you want to use
  1. The code should look something like this:

  1. Click Save Changes.

Test your conditional content blocks

  1. Create a test page.
  2. Open the page in Edit mode.
  3. On the editor toolbar, click the Formatting styles menu. 
  4. Verify your drop-down menu contains your conditional content group:
  5. Add the conditional block to the page, add text and click Save.
  6. Have users who are members of your group and users who are not members of the group visit the page.
  7. Have the users verify whether they can or cannot see the conditionalized content.

How to remove conditional content formatting

  1. Open the page in Edit mode.
  2. Highlight the conditional content on the page with your cursor.
  3. On the editor toolbar, click the Formatting styles menu. 
  4. Click the conditional content style that is currently highlighted.

Conditional content is toggled similar to formats like bold and italic. Applying the style twice restores the content to the original state.

Add more than one group to a statement

If you want more than one group to be able to see the same content, use any of the following statements.

OR parameter

By using the OR parameter (double straight bars) in your statement, users who are members of either the Administrators group OR the Editors group will be able to see the conditional content.

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

AND parameter

By using the AND parameter (double ampersands) in your statement, users who are members of both the Administrators group AND the Editors group will be able to see the conditional content.

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

NOT parameter

By using the NOT parameter (single exlcamation mark) in your statement, users who are NOT members of the Administrators group will be able to see the conditional content.

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

  • Was this article helpful?