Skip to main content
MindTouch Success Center

Create custom conditional content groups

This page applies to:MindTouch (current)

This article provides instructions for how to create conditional content blocks to display sections of text to specified users only.
 

Why should I 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.

 

How to create your custom conditional content blocks


To create your custom conditional content block, follow the steps below:

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

Step 2:  Create groups

Next, it is time to 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.  

Step 3:  Set up your conditional classes

This section requires some DekiScripting. 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.

Step 4:  Set up conditional classes for reuse

Once you have tested the above code with the groups you have set up, create conditional content blocks your authors can easily access from within the MindTouch editor.  To do so follow these steps:

  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.

Step 5:  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:

  1. Add the conditional block to the page, add text and click Save.

When you select the block, it may be hard to see where the block starts and ends. Selecting View > Show blocks in the editor toolbar displays the boundaries of the block. To exit out of a block click Shift+Enter.

  1. Have users who are members of your group and users who are not members of the group visit the page.
  2. Have the users verify whether they can or cannot see the conditionalized content.
     

How to remove conditional content formatting


To turn a conditional content region back to regular content:

  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.


How to 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>


What's next?


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