Confluence macro to include sub pages not displaying html correctly after confluence upgrade
Asked by Daniel Hurrell:

Hi there,

After upgrading Confluence from version 6.13.13 to 7.13.0, my user macro to include sub pages stopped displaying Html correctly, I have looked through similar issues and people mention to add Html to the end of variables where html is to be used, and I did. Where this fixed the page heading being displayed, the actual content of the page is being displayed as raw Html eg: \<h1\>TestText\</h1\>.

The code is as follows:

## [@Param](/t5/user/viewprofilepage/user-id/1345631) Page:title=Page\|type=confluence-content\|desc=Target page  
#if ($paramPage.contains(':'))  
#set ( $strArrayHTML = \[\] )  
#foreach($str in $paramPage.split(':'))  
#set($dummyHTML = $strArrayHTML.add($str)) ## Assign returnval to avoid printing 'true'.  
#end  
#set($spacekey = $strArrayHTML.get(0).trim())  
#set($pagetitle = $strArrayHTML.get(1).trim())  

#else  
#set($spacekey = $content.getSpaceKey()) ## Current spacekey  
#set($pagetitle = $paramPage.trim())  
#end

#set( $headingLevelStringHTML= "h" + $level.toString())

##FUNCTION  
#macro( function $level,$pageTemp)

#set( $headingLevelStringHTML= "h" + $level.toString())  
#set ($heading1HTML = "\<" + $headingLevelStringHTML + "\>")  
#set ($heading2HTML = "\<" + $headingLevelStringHTML + "/\>")

<br />

\<header\> $heading1HTML $pageTemp $heading2HTML \</header\>  
\<header\> $spacekey \</header\>  
\<header\> $pageTemp\</header\>

<br />

#set($globalHelper = $action.getHelper())  
#set($renderedHtml = $globalHelper.renderConfluenceMacro("{include:$spacekey:$pageTemp}"))

#set($level1 = $level +1)  
#set($level2 = $level +2)  
#set($level3 = $level +3)  
#set($level4 = $level +4)  
#set($level5 = $level +5)  
#set($level6 = $level +6)

#set( $headingLevelString1HTML= "h" + $level1.toString())  
#set( $headingLevelString2HTML= "h" + $level2.toString())  
#set( $headingLevelString3HTML= "h" + $level3.toString())  
#set( $headingLevelString4HTML= "h" + $level4.toString())  
#set( $headingLevelString5HTML= "h" + $level5.toString())  
#set( $headingLevelString6HTML= "h" + $level6.toString())

<br />

##INDENT ALL HEADINGS ON CURRENT PAGE  
$renderedHtml.replaceAll("h6",$headingLevelString6HTML).replaceAll("h5",$headingLevelString5HTML).replaceAll("h4",$headingLevelString4HTML).replaceAll("h3",$headingLevelString3HTML).replaceAll("h2",$headingLevelString2HTML).replaceAll("h1",$headingLevelString1HTML)

<br />

#set($childpages = $pageManager.getPage($spacekey,$pageTemp).getSortedChildren())  
#if($childpages.size()\>0) ##Check if there are childpages

#set($levelPrev = $level)  
#set($level = $level +1)  

#foreach($page in $childpages)  
#function($level,$page.getTitle())  
#end  

#set($level = $levelPrev)  
#set($levelPrev= $level - 1)  

#end  
#end

##CALLING FUNCTION  
#set( $level = 1 )  
#function($level,$pagetitle)

![UserMacroError.png](/t5/image/serverpage/image-id/180710i8823BF1747B6D0BB/image-size/large?v=v2&px=999 "UserMacroError.png")

Circled in red is the html that works(

\<header\> $heading1HTML $pageTemp $heading2HTML \</header\>  
\<header\> $spacekey \</header\>  
\<header\> $pageTemp\</header\>

),

and in blue is the content that displays within the html tags.(

$renderedHtml.replaceAll("h6",$headingLevelString6HTML).replaceAll("h5",$headingLevelString5HTML).replaceAll("h4",$headingLevelString4HTML).replaceAll("h3",$headingLevelString3HTML).replaceAll("h2",$headingLevelString2HTML).replaceAll("h1",$headingLevelString1HTML)

)

The page should look like this:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/180723i69715E893B17AED3/image-size/large?v=v2&px=999 "image.png")

Incase anyone asks, I have tried to add Html to the end of almost every variable and that didn't work either.

Any help would be appreciated.


Answers:
author: Bill Bailey
body: What is interesting is that it displayed correctly for one page, and not the other? Am I understanding correctly?

Is this behavior order dependent? Is there a difference between the content of the two test pages?

comments: author: Daniel Hurrell
body: Hi there, thanks for the quick response. Firstly they are on two different versions of confluence, the incorrectly formatted is on the newer version and the correctly formatted is on the old. I actually managed to figure it out, it was the renderedHtml variable, I assume it was somehow parsed to a string even though it had the Html at the end to render the html, so I just set that to a variable with the render Html tag at the end and it worked. (Sorry if the explanation isn't clear, very new to the VTL language)

#set($rendHtml=$renderedHtml.replaceAll("h6",$headinglevelString6HTML).replaceAll("h5",$headinglevelString5HTML).replaceAll("h4",$headinglevelString4HTML).replaceAll("h3",$headinglevelString3HTML).replaceAll("h2",$headinglevelString2HTML).replaceAll("h1",$headinglevelString1HTML))  
$rendHtml


author: Bill Bailey
body: That is actually not VTL, but more an issue of which Java methods are exposed to Velocity in Confluence. And it changes between major versions, unfortunately,

Thanks for posting your solution as it will help other in the future. I am going through a Confluence 6.x to 7.x upgrade now.


author: Daniel Hurrell
body: Oh, I understand, thanks for the clarification. Good luck!


author: Fabian Lim
body: Hi [@Daniel Hurrell](/t5/user/viewprofilepage/user-id/4563603)

Welcome to the community.

I recommend you also open up a ticket with atlassian support: <https://support.atlassian.com/>

Regards

comments: author: Daniel Hurrell
body: Hi Fabian, thank you very much.

I solved this not much later after I submitted the question.


Tags: html

user-macro