This is the documentation for an older version of Scroll Viewport. Here you can view the most up-to-date version of the Scroll Viewport documentation.

User Search Recipe

This recipe explains how to implement search forms for searching users.

This recipe is based on the Search Template Recipe. There is not that much difference to this recipe other than the form parameters – look at that page to learn how to build the user search.

Creating a Search Form

Add the following HTML code to a template for single input field search form:

#set($search = "/search")
#if ($stringUtils.equals(${viewport.link}, "/") == false)
	#set($search = "${viewport.link}/search")
#end
<form action="$search" method="GET">
    <input id="searchQuery" name="q" type="text" placeholder="Enter Search" value="$!searchRequest.queryString">
    <input type="hidden" name="t" value="user" >
	<input type="submit" value="Submit">
</form>

A list of available content types, as shown with <input type="hidden" name="t" value="user"> can be found in the Search Template Recipe.

Displaying User Details in the Search Results

Create a template file search-user.vm in the top level of the theme directory:

search-user.vm
#foreach($searchResult in $searchResults.results)
    <li>
        <h3>$searchResult.displayTitle</h3>
        <p>Position: $searchResult.getProperty("confluence.user.profile.position")</p>
        <p>Location: $searchResult.getProperty("confluence.user.profile.location")</p>
        <p>Phone: $searchResult.getProperty("confluence.user.profile.phone")</p>
        <p>Department: $searchResult.getProperty("confluence.user.profile.department")</p>
    </li>
#end

Scroll Viewport will only use the search-user.vm template if the search is limited to users only (&t=user). If other content types are searched, Scroll Viewport will use the search.vm template.

Extended User Search with the User Profile Plugin

Define Search Fields

With User Profile Plugin, you can also search profile data such as location, department, phone number etc. (The built-in Confluence search only searches name, email, and full name.)

To add additional search fields, add the following HTML code to a template to define the search form:

#set($search = "/search")
#if ($stringUtils.equals(${viewport.link}, "/") == false)
	#set($search = "${viewport.link}/search")
#end
<form action="$search" method="GET" class="form-inline text-center" role="form" style="margin-bottom: 2em;">
    <input class="form-control input-lg" id="searchQuery" name="q" type="text" placeholder="Enter Search" value="$!searchRequest.queryString" />
    <input type="hidden" name="t" value="user" />
    <input type="hidden" name="fields" value="Department,Location" />
</form>

Note the fields parameter – this specifies which Scroll Viewport should look for.

Next steps

Check out how to Display Extended User Details from the User Profile Plugin.