"Error occurred rendering template content" with User Macros

Nicolas Casel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2016

Hi all,

Before upgrading to Confluence v 5.10.5, my two custom User Macros worked fine. Here is the code of one of them:

 

## Macro name: number-of-comments
## Visibility: Visible only to system administrators in the Macro Browser
## Macro title: Number of comments
## Description: Returns the number of comments for a given page
## Categories: Confluence content, Reporting
## Macro body processing: No macro body
##
## Developed by: Nicolas Casel
## Date created: 03.07.2016
## Installed by: Nicolas Casel
## @param PageID:title=Page ID|type=int|required=false|desc=ID of page to count comments
##
## Check for page id parameter, otherwise use default of current page
#if (!$paramPageID)
#set ($paramPageID=$content.id)
#end
##
#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )
#set( $commentManager=$containerContext.getComponent('commentManager') )
##
#set ($targetPage = $action.page)
## Set up integer object to handle string conversion of page id
#set($Integer = 0)
##
#if ($pageManager)
#set ($targetPage = $pageManager.getPage($Integer.parseInt($paramPageID)))
#end
##
#set($count = $commentManager.countComments($targetPage))
#if ($commentManager)
##<span class="commentcount">$count</span>
<aui-badge style="background-color: #d04437; color: white;">$count</aui-badge>
#end
#end

 

Since Confluence v 5.10.5, I get this message:

Error rendering macro 'number-of-comments' : Error occurred rendering template content

 

Any idea of the reason? Thank you!

 

1 answer

1 vote
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2016

The easiest way to see what is wrong is to look in the log file <confluence_home_directory>/logs/atlassian-confluence.log. Whenever it shows an "Error occurred rendering template content", there will be an accompanying entry in the log file with more details.

One thing you might try is to change 

#set ($targetPage = $action.page)

to

#set ($targetPage = $content)

Nicolas Casel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2016

The easiest way to see what is wrong is to look in the log file <confluence_home_directory>/logs/atlassian-confluence.log

Thanks for this insight.

In this case, I found the solution: removing the last:

#end

(last line)

 

Like Elena Denoeva likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events