DougS
14 years agoKhoros Oracle
Display different custom content modules to users of different ranks (Freemarker)
Big thanks to Kaela for this information!
Description
This component displays different "custom content" modules based on what rank a user has. If they have the "Lithium Guru" rank, they see custom content module 3. If they have the "Wayfarer" rank they see custom content module 2. If they are logged in but have neither rank, they see custom content module 1. If they are not logged in, they do not see a custom content module in this component.
Requirements
Lithium version 9.18 or higher, Lithium Studio
How to add this to a Lithium community
There are two parts to displaying custom content based on user ranks:
- Create a component that contains the display logic
- Add the component to pages
To create the logic component:
- Go to Studio > Components.
- Click New Component. Enter a name for the component (for example, custom-content-by-rank) and click Create.
- Add the following markup to the component:
<#if user.registered > <#assign rank = restadmin("/users/id/${user.id?c}/ranking").ranking /> <#if rank.name?? && (rank.name == "Lithium Guru")> <@component id="common.widget.custom-content" name="3" panel="true" /> <#elseif rank.name?? && (rank.name == "Wayfarer")> <@component id="common.widget.custom-content" name="2" panel="true" /> <#else> <@component id="common.widget.custom-content" name="1" panel="true" /> </#if> </#if>
- Click Save.
To place the element on a page:
- Choose Community Admin > Content > Custom Content.
- Select each of the first three custom content modules and add the content you want to display to each rank.
Example
Go to the Code Sample 4 Example Page to see this in action.