Stand with Ukraine 🇺🇦

Content by User — Confluence Cloud Macro

confluence-content

The macro generates a list of content created by a specified user (or the current user by default) across your Confluence site. The macro uses CQL (Confluence Query Language) to query the content based on creator and content type, and displays the results in a styled list.

Try for free

User Parameters

User

Select a user to show their content

Content Type

Select content types

Template

#set($user = $parameters.user)
#set($contentTypeParam = $parameters.contentType)
#set($limit = 50) ## Limit the results to 50 items

## Prepare content types for CQL query, defaulting to "page, blogpost, attachment" if none are specified
#if($contentTypeParam)
#set($contentTypes = $contentTypeParam.split(","))
#else
#set($contentTypes = ["page", "blogpost", "attachment"])
#end
#set($contentTypeQuery = $StringUtils.join($contentTypes, "', '"))

## CQL query setup based on user parameter
#if($user)
#set($cqlQuery = "creator = '$user' AND type IN ('$contentTypeQuery') ORDER BY created DESC")
#else
#set($cqlQuery = "creator = currentUser() AND type IN ('$contentTypeQuery') ORDER BY created DESC")
#end

## Execute the CQL query, expanding space and version data
#set($response = $ConfluenceManager.get("/wiki/rest/api/content/search?cql=$cqlQuery&limit=$limit&expand=space,version"))

## Initialize userName to display in the header
#set($userName = "Current user")
#if($response.results.size() > 0)
#set($userName = $response.results[0].version.by.displayName)
#end

<ul>
    <p style="margin-bottom: 10px;">
        Content created by <strong>$userName</strong>:
    </p>
    #if($response.results.size() > 0)
    #foreach($content in $response.results)
    <li style="list-style-type: circle; margin-left: 30px;">
        <span class="aui-lozenge aui-lozenge-subtle aui-lozenge-success">$content.type</span>
        <a href="${response._links.base}$content._links.webui" target="_blank">$content.title</a>
        <span style="color: grey;">(in $content.space.name space)</span>
    </li>
    #end
    #else
    <li>No content found for <strong>$userName</strong>.</li>
    #end
</ul>