Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,841
Community Members
 
Community Events
165
Community Groups

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

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

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

324 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you