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)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.