How to display different appearance for different users using Confluence layouts

Still need help?

The Atlassian Community is here for you.

Ask the community

This guide is for informational purposes and is not eligible for support from Atlassian.  If you have any questions about the information on this page, please reach out to our community at Atlassian Answers for help.

Purpose

Sometimes, we want anonymous users to see different contents in the dashboard or any other Confluence pages. Or we want to display different contents for different groups of users. This guide provides you some ways in which this can be achieved.
(info) In order to implement these steps you will need to have administrator access.

 Solution

The process involves customizing the Layouts in Administration -> Layouts or Space Admin -> Layouts

1. To Display Different Contents for Anonymous Users

Add the following code:

#if ($helper.action.remoteUser) 
	this can only be viewed by registered users (those users who are logged into Confluence)
#else
	this can only be viewed by anonymous users
#end

2. To Display Different Contents for A Specific User

Add the following code:

#if ($helper.action.remoteUser.name == 'confuser') 
	this can only be viewed by confuser
#else
	this can be viewed by anyone except confuser
#end


3. To Display Different Contents for Different Groups

Add the following code:

#if ($userAccessor.hasMembership('confluence-administrators', $helper.action.remoteUser.name)) 
	this can only be viewed by users in "confluence-administrators" group
#elseif ($userAccessor.hasMembership('confluence-users', $helper.action.remoteUser.name))
	this can only be viewed by users in "confluence-users" group
#else
	this can only be viewed by users who are NOT in "confluence-users" and "confluence-administrators" groups
#end


4. To Redirect and Display Different Contents for Certain Groups - Useful for Jira Service Desk Customers

Some Jira Service Customers will attempt to access articles directly from the Confluence Base URL instead of the Jira Service Desk portal. To avoid permission errors when customers attempt to access the Confluence base URL you can redirect them to the space or Service Desk portal with permissions they have to view.

Add the following code:

#if ($userAccessor.hasMembership('jira-servicedesk-customers', $helper.action.remoteUser.name))
## This only redirects users of the group "jira-servicedesk-customers"
	 <script>
                window.onload = function() {
                  if (window.location.href.includes("<INSERT SPACEKEY>") == false) {
## <INSERT SPACEKEY> should match the only space/s the group has permissions to view
                    window.location.replace("<INTENDED SPACE OR JIRA PORTAL URL>");
## <INTENDED SPACE OR JIRA PORTAL URL> is the URL you want to redirect users of that group. Can be to the only space they have access, back to the Service Desk portal or anywhere.
                  }
                }
        </script>
#end
Last modified on Jan 3, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.