Skip to main content

Conditionalize sections of an article

This page applies to:MindTouch Responsive

This article addresses how to restrict content to only certain users of your site. Using conditional content on a page is not only a great way to personalize the experience for your users, but—and more importantly—it provides a mechanism for you to keep your proprietary information proprietary.  In MindTouch, any content can be viewed on a need-to-know basis.

When to use conditional content

Use conditional content whenever you need to control who sees what information on page, as in the following examples: 

  • Internal users need access to proprietary information on a page. 
  • Technical notes to your support team should only seen by your support team.
  • Editors need to "hide" information until it is vetted. 


How search engines deal with conditional content

Search engines (including the MindTouch search engine) can only find content you make publicly available, i.e. content you make available to anonymous users. Even if your site is public (which we recommend so your site can get indexed and ranked by web search engines), with conditional content, you control which content search engines are allowed to index and to display on their search engine results pages (SERPs). Search engines cannot see any content you conditionalized for community members (they have to be logged in to see information) or pro members (they too have to be logged in but also have various degrees of contribution privileges). In short, search engines can only see public content or content that is conditionalized for anonymous users.


Conditionalize content

  1. Open the Styles menu.​


  1. Select one of the following options from the Styles drop-down menu, depending on who should see the conditionalized content:
  • Conditional text (anonymous only)
  • Conditional text (community member only)
  • Conditional text (pro member only)    

Image  of conditional text options in the styles menu

  1. Add your text to the conditional text box.

Image of a conditional text box on a page

  1. Click Save.


Remove conditional content

  1. Highlight the conditional content.
  2. Open the Styles menu.
  3. Click the highlighted conditional content style.

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

Create custom conditional text blocks for specific groups

Implementation of conditional content for specific groups, requires some coding experience.

Before we get started with the implementation, identify the users you want to segment out for your content. In this tutorial, we will create two (2) user groups: An Editors group and an Administrators group. 

Create groups

Once you have identified our groups, create your groups. In this case, the Editors and Administrators groups.

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.  

Test your conditional classes

This section require some DekiScripting. Below are examples that will give you a starting point.

  1. Create a New page.
  2. In the editor toolbar, click View > Source.  
  3. Once in source view,  add the following code:
<div if="user.groups['Administrators']">Sample</div>

The above conditional statement checks if the person accessing the article is in the Administrators group.

  1. Have administrators visit the page and verify they see the word "Sample."  
  2. Repeat the same steps for the Editors group.

Set up your conditional classes

Once you have tested the above code with the groups you have set up, create the custom conditional blocks in the editor for authors to use:

  1. Navigate to Site toolsControl panel > System Settings >Editor.
  2. Place 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 : { 'if' : 'user.groups["Administrators"]'} });
  1. Replace he highlighted items above 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 with the conditional block you want to use.
  1. The editor settings (minus any other code that may be present) should look something like this:

Image of the editor configuration dialog with conditional block code

  1. Click Save
  2. Open a page in Edit mode and verify the custom conditional block shows up in the Styles menu. 

Image of a custom conditional block in the editor

  1. Write any text on the page.
  2. Highlight the text and apply the custom conditional block.

To exit out of a block click SHIFT+ENTER. 

  1. Save the page.
  2. Verify content is only seen by intended users.


Text in a custom conditional block looks the same as any other text. There is no special or formatting associated with custom conditional text blocks. To view the boundaries of the custom block, view the page in Source mode. 


Add more than one group to a conditional block

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.

Use the OR statement

For example, by adding the OR parameter (double straight bars ||) to your statement, members of the Administrators group or the Editors group will be able to see the content within that specific statement. 

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

By adding the AND parameter (double ampersands &&) to your statement, members of the Administrators group and the Editors group will be able to see the content within that specific statement. 

<div if="user.groups['Administrators'] && user.groups['Editors']">Sample</div>
  • Was this article helpful?