Using alternative forms based on user-specific information

   —   
You want to use the User contributions (Wiki) module of Kentico CMS to allow the users contribute to your web site. On top of that, based on the role current user belongs to; you want to control how detailed editing form is displayed. This KB article demonstrates how to achieve this in Kentico CMS.

As you’ll see there are several ways how the outlined task could be achieved.

1. Using macro expression for the alternative form name in a web part configuration

Let’s imagine you’ve added custom field to the User system table. Field represents a flag on whether the user is VIP member. If you’re not familiar with the custom system fields, please refer to the System tables and custom fields section in the Kentico CMS Dev Guide.

1_VIP_User_Custom_field.png

When you place the Contribution list web part on your page you’re able to specify what alternative form should be used when user tries to create a new document of allowed document type. If you use the macro expression for the ‘Alternative form name’ field in the configuration of the Contribution list web part, you can dynamically evaluate form name based on the particular information related to the current user- the VIP status for example. Simply enter the Contribution list web part properties and for the ‘Alternative form name’ field use macro expression as ‘CMS.News.{%cmscontext.currentuser.userisvip|(equals)True|(truevalue)vip|(falsevalue)notvip%}’.

2_Contribution_list_macro_config.png

Macro will be evaluated as ‘vip’ if the current user has the ‘Is VIP’ flag set to true. Otherwise it will return ‘notvip’. We've created two alternative forms for the ‘CMS.News’ document type with code name ‘vip’ or ‘notvip’ earlier. The one according the user status is used to create/edit new document afterwards.

2. Using the ‘Display to roles’ setting for the web part

If you want to display user with alternative form based on the role user belongs to you might use the ‘Display to roles’ setting- the default ‘Contribution list’ web part setting found under the ‘Visibility’ section. Place two contribution web parts on the same page and set its ‘Display to roles’ values to different roles. This approach is useful in the case you’re fine with reusing the most of the page's content, however, in some scenarios you might want to have different page content for different roles as well. The solution is described below.

3. Using the document level security settings

If your content varies along with the alternative form you may want to use document level permissions to influent what content (page) will be displayed for the particular group of users. Create two pages, define its content, place contribution web parts using different alternative form on each page and setup the security for pages through the CMS Desk-> Content-> <page>-> Edit-> Properties-> Security-> Permissions.

-kj-


See also: Macro expressions

Applies to: 4.x, 5.x
Share this article on   LinkedIn Google+

Karol Jarkovsky

Director of Product

Comments