help with creating user macro similar to content by label
Asked by Karina Green:

I am trying to create a user macro similar to content by label with a few changes in the markup along with adding pagination. But I do not know what I should be setting the contents variable to, I cannot seem to figure out how to return the results on the page.

This the code I have, What do I need to set the contents variable to and what is the syntax for doing this?

<br />

#\* @vtlvariable name="contents" type="java.util.List\<com.atlassian.confluence.core.ContentEntityObject\>" \*#  
#\* @vtlvariable name="excerpter" type="com.atlassian.confluence.plugins.macros.advanced.xhtml.AdvancedMacrosExcerpter" \*#  
#\* @vtlvariable name="excerptType" type="com.atlassian.confluence.plugins.macros.advanced.xhtml.ExcerptType" \*#  
#\* @vtlvariable name="i18n" type="com.atlassian.confluence.util.i18n.I18NBean" \*#  
#\* @vtlvariable name="limitLabelLinksToSpace" type="boolean" \*#  
#\* @vtlvariable name="req" type="javax.servlet.http.HttpServletRequest" \*#  
#\* @vtlvariable name="showLabels" type="boolean" \*#  
#\* @vtlvariable name="showSpace" type="boolean" \*#  
#\* @vtlvariable name="staticResourceUrlPrefix" type="java.lang.String" \*#  
#\* @vtlvariable name="title" type="java.lang.String" \*#  
#\* @vtlvariable name="stringUtils" type="org.apache.commons.lang.StringUtils" \*#

## [@Param](/t5/user/viewprofilepage/user-id/1345631) labels:title=Label\|type=confluence-content\|required=true  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) sort:title=Sort By\|type=enum\|enumValues=title, creation, modified\|required=true  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) reverse:title=Reverse Sort\|type=boolean\|desc="Used only in conjunction with the 'Sort By parameter."  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) limitLabelLinksToSpace:title=Maximum Number of Pages\|type=string\|default=15  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) title:title=List Title\|type=string\|default=Stories by label  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) showLabels:title=Show Labels for Each Page\|type=boolean\|default=false  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) showSpace:title=Show Space Name for Each Page\|type=boolean\|default=false  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) excerpt:title=Excerpt Display\|type=enum\|enumValues=none, simple, rich content\|required true\|desc=How to display excerpts for each page.  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) showpageribbon:title=Show Page Ribbon\|type=boolean\|default=true  
## $helper.renderConfluenceMacro("{next_previous_links:WrapAtEnd=false}")  
## $helper.renderConfluenceMacro())

#if ($paramtitle)  
\<h3\>$paramtitle\</h3\>  
#end

<br />

#if ($contents.length() \> 0)  
\<ul class="content-by-label"\>  
#foreach ($content in $contents)  
\<li\>  
\<div\>  
#contentIconWithLinkPrefix($content $staticResourceUrlPrefix)  
\</div\>

\<div class="details"\>  
#contentHrefWithLinkPrefix($content $req.contextPath)  
#if ($paramshowSpace) #contentOther($content) #end

#set ($excerptHtml = $excerpter.createExcerpt($content, $paramexcerptType) )  
#if ($stringUtils.isNotBlank($excerptHtml))  
\<span class="smalltext"\> $excerptHtml\</span\>  
\<div\> this is a test\</div\>  
#end

#if ($paramshowLabels)  
\<div class="label-details"\>  
#if( $paramlimitLabelLinksToSpace )  
#set( $spaceKey = $content.getSpaceKey() )  
#else  
#set( $spaceKey = "" )  
#end

#set ($paramlabels = $content.getVisibleLabels($action.authenticatedUser))  
#parse("/com/atlassian/confluence/plugins/labels/components/labels-list.vm")  
\</div\>  
#end  
\</div\>  
\</li\>  
#end

#if ($paramshowpageribbon)  
\<div style="text-align:center; font-size: 14px;"\>  
#if($pager.hasPrev)  
\<a href="$pager.prevLink"\>\<\<\</a\>  
#end  
#foreach ($page in $pager.pages)  
\<a href="$page.link" class="#if($page.current) current #end"\>  
$page.number  
\</a\>  
#end  

#if($pager.hasNext)  
\<a href="$pager.nextLink"\>\>\>\</a\>  
#end  
\</div\>  

\</ul\>

#end  
#else  
\<div class="content-by-label macro-blank-experience"\>  
\<strong class="content-label-header"\>$i18n.getText('contentbylabel.emptymacro.label')\</strong\>  
\<p\>$i18n.getText('contentbylabel.emptymacro.content')\</p\>  
\</div\>  
#end


Answers:
author: Diego
body: Hello there Karina!

Some time ago another customer had the same need and came up with this thread, maybe it could help you out as well!!

**[pagination with macro](https://community.atlassian.com/t5/Confluence-questions/pagination-with-macro/qaq-p/49689)**

Let us know!

comments: author: Karina Green
body: Thank you, but before I can even resolve the pagination issue, I have to have the content returned. I am able to input the parameters of the macro, but I cannot get any content to be returned, I seem to be missing something in the code to return the content I want. I guess I do not know what the $contents variable needs to be set to, or what helpers I need if any.


Tags: content-by-label