Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

User Macro: Related Content

Confluence had a list of shared user macros (which can't be updated anymore). I found one that was useful however doesn't currently work in Confluence:

https://confluence.atlassian.com/display/DISC/Related+Content

I updated it (likely there is still work to be done to it, not sure if I'll put more effort though) and thought of returning the favor by sharing the new version back to the community as it was intended. If I happen to update it, I'll update it on this post as well.

So here goes:

=============================

## @Param labels:title=Labels|type=string|desc=Comma-separated list of additional labels
## @Param author:title=Author|type=username|desc=Filter by author.
## @Param type:title=Document Type|type=enum|enumValues=page,blogpost|desc=Only show documents matching this type.
## @Param showLabels:title=Show Labels for Each Page|type=boolean
## @Param showSpace:title=Show Space Name for Each Page|type=boolean
## @Param title:title=List Title|type=string
## @Param maxResults:title=Maximum number of Pages|default=5|type=string
## @Param excerpt:title=Excerpt Display|type=enum|enumValues=none,simple,rich content|desc=How to display excerpts for each page.
## @Param space:title=Space|type=spacekey|desc=Filter by space.
## @Param sort:title=Sort By|type=enum|enumValues=title,creation,modified
## @Param reverse:title=Reverse Sort|type=boolean|desc=Used only in conjunction with the 'Sort By' parameter.

 

#set($wiki="")
#set($globalHelper=$action.getHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($labelList=$content.getGlobalLabels($action.getRemoteUser()))
#if($labelList.size() > 0)

#set($labels="")
#foreach( $label in $labelList )
#if($labels == '')
#set($labels="'"+$label+"'")
#else
#set($labels=$labels+","+"'"+$label+"'")
#end
#end

#if($paramlabels)
#set($labels=$labels + ", " + $paramlabels)
#end

#set($wiki="{contentbylabel:cql=")
#set($wiki=$wiki + "label in ($labels)")
#if($paramauthor)
#set($wiki=$wiki + "|creator=$paramauthor")
#end
#if($paramtype)
#set($wiki=$wiki + "|type=$paramtype")
#end
#if($paramshowLabels)
#set($wiki=$wiki + "|showLabels=$paramshowLabels")
#end
#if($paramshowSpace)
#set($wiki=$wiki + "|showSpace=$paramshowSpace")
#end
#if($paramtitle)
#set($wiki=$wiki + "|title=$paramtitle")
#end
#if($parammaxResults)
#set($wiki=$wiki + "|max=$parammaxResults")
#end
#if($paramexcerpt)
#set($wiki=$wiki + "|excerptType=$paramexcerpt")
#end
#if($paramspace)
#set($wiki=$wiki + "|space=$paramspace")
#end
#if($paramspaces)
#set($wiki=$wiki + "|space=$paramspaces")
#end
#if($paramsort)
#set($wiki=$wiki + "|sort=$paramsort")
#end
#if($paramreverse)
#set($wiki=$wiki + "|reverse=$paramreverse")
#end
#set($wiki=$wiki + "}")
#end
#set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else ## we are e. g. in Global Template Preview
#set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end
## remove leading <p> and trailing </p>
#if($xhtml.startsWith("<p>",0) && $xhtml.endsWith("</p>"))
#set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
#set($xhtml=$xhtml.substring(3,$len))
#end
${xhtml}

1 comment

BAPrice June 25, 2021

I haven't tested, but this is a great contribution.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events