Include Page Macro: Is there a known issue using markup within a custom User Macro?

Shaun Grose February 6, 2020

Hi community, I'm running into a really annoying issue with the "Include Page" macro within a User Macro.

Background

We have a large team, and many people have different permissions to different content, including a few reference pages for anonymous users in the larger organisation. If the user doesn't have access to the page being referenced by an Include macro, the error message looks a bit ugly, so we want to provide some better content instead. Hence we have written a User Macro that outputs the Include Page macro if the user does have access, otherwise we output an HTML block.

Problem

The 'include' macro works fine on its own, but if I create it with markup using a custom User Macro, it doesn't load the referenced page, it loads the current page within itself.

Example: I have two pages: CurrentPage and LookupPage:

1. I can add the Include Page macro on my page, 'CurrentPage'

{include:mySpace:LookupPage|nopanel = true}

 As expected, this renders correctly:

{CurrentPage Content}
- {LookupPage Content}
{Rest of CurrentPage Content}

2. If I output the macro via the User Macro:

#set($spacekey = "mySpace")
#set($pageName = "LookupPage")
#set($macro = "{include:${spacekey}:${pageName}|nopanel = true}")

#if ($permissionHelper.canViewPage($action.remoteUser, $spacekey, $pageName))
$action.getHelper().renderConfluenceMacro($macro)
#else
<span>some content</span>
#end

In the Edit Macro Preview for my User Macro, I correctly see the content from LookupPage, as I should, but when I publish the page, instead of seeing LookupPage content where the macro is, I see the current page nested within itself:

{CurrentPage Content}

 -  {CurrentPage Content}
 -  (Error that CurrentPage is already referenced)
 -  {Rest of CurrentPage Content}

{Rest of CurrentPage Content}

I've tried just outputting the $macro text and feeding into the markup macro to make sure there wasn't anything dumb getting written out, but it's definitely getting calculated correctly (plus, I wouldn't see LookupPage content in the Preview if it was wrong).

Has anyone run into this issue? Is there something I'm doing wrong?

(Minor edit for clarity)

1 answer

0 votes
Shaun Grose March 4, 2020

:-(
No ideas?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events