Hi, I want to create an annotated variant of the Include Page macro in confluence. My version should surround the included page in a panel and add a caption (included from <link>).
I got it working for pages in the same space, but not for pages in a different space, because I do not know how to set the <ri:page ri:space-key> parameter from my ## @param ip:title=Included Page|type=confluence-content|required=true|desc=Select a page to include parameter:
Example storage format for an include page macro:
<p><ac:structured-macro ac:name="include" ac:schema-version="1" ac:macro-id="7c3338cb-d85f-4aeb-8c61-5fb36e24d61f"><ac:parameter ac:name=""><ac:link><ri:page ri:space-key="TFML" ri:content-title="Instructions for use" /></ac:link></ac:parameter></ac:structured-macro></p>
My user macro:
## @param ip:title=Included Page|type=confluence-content|required=true|desc=Select a page to include
## @param Title:title=Title|type=string|desc=Title
<ac:structured-macro ac:name="panel">
<ac:parameter ac:name="borderColor">#6699CC</ac:parameter>
<ac:parameter ac:name="borderWidth">1</ac:parameter>
<ac:parameter ac:name="title">$!paramTitle</ac:parameter>
<ac:rich-text-body>
<p><ac:structured-macro ac:name="include" ><ac:parameter ac:name="">
<ac:link><ri:page ri:content-title="$paramip" /></ac:link></ac:parameter>
</ac:structured-macro></p>
<div><sub><em>(included from <ac:link><ri:page ri:content-title="$paramip" /></ac:link>)</em></sub></div>
</ac:rich-text-body>
</ac:structured-macro>
-------------
Of course, I could add a second @param where the user has to enter the space name, but that would be independend of the page parameter and allow invalid input combinations.
How can I extract the space from the confluence-content parameter or how can I construct correct links only using the confluence-content parameter?
(if I use a same-space-page in my macro, it works as expected, but for a foreign-space-page, this error message is rendered:
I literally spent Tuesday creating this same macro. Today I found your post! (It would have saved me all those hours, but to be honest I think I learned a lot more doing it myself.)
Does this help?
## Macro title: Page Link with Ref
## Macro has a body: No
## Body processing: No Macro Body
## @param PageToInclude:title=Page to Include|type=confluence-content|required=true|desc=To specify a page in a different space, use SPACEKEY:Page Title.
#if ( $paramPageToInclude.indexOf(":") == -1 )
#set ( $spaceKey = $space.key )
#set ( $contentTitle = $paramPageToInclude)
#else
#foreach ( $part in $paramPageToInclude.split(":") )
#set ( $spaceKey = $part )
#break
#end
#foreach ( $part in $paramPageToInclude.split(":") )
#set ( $contentTitle = $part )
#end
#end
#set ( $linkSpace = $spaceManager.getSpace($spaceKey) )
#set ( $spacetitle = $linkSpace.getName())
#if ($spacetitle.contains('Space'))
#else
#set ( $spacetitle = "$spacetitle Space")
#end
<em>
This is a link to
<ac:link>
<ri:page ri:content-title="$!contentTitle" ri:space-key="$spaceKey"/> $!paramPageToInclude
</ac:link>
in the <a href="$linkSpace.homePage.urlPath"> $spacetitle. </a>
<br>
<ac:macro ac:name="panel">
<ac:parameter ac:name="titleBGColor">lightyellow</ac:parameter>
<ac:parameter ac:name="borderStyle">solid</ac:parameter>
<ac:parameter ac:name="borderColor">#6699CC</ac:parameter>
<ac:parameter ac:name="borderWidth">1</ac:parameter>
<ac:parameter ac:name="titleColor">#000000</ac:parameter>
## <ac:parameter ac:name="title">This is a link to "$!contentTitle" in the $spacetitle.</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="include">
<ac:parameter ac:name="">
<ac:link>
<ri:page ri:content-title="$contentTitle" ri:space-key="$spaceKey"/>
</ac:link>
</ac:parameter>
</ac:structured-macro>
</ac:rich-text-body>
</ac:macro>
Thank you very much, this helps a lot!
Very nice solution, supports auto-complete in the parameter editor including spaces.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That unclear part using `foreach` can be also rewritten this way:
#set ($delPos = $paramPageToInclude.indexOf(":"))
#if ($delPos == -1)
#set ($spaceKey = $space.key)
#set ($contentTitle = $paramPageToInclude)
#else
#set ($spaceKey = $paramPageToInclude.substring(0, $delPos))
#set ($delPos = $delPos + 1) ## shifting delimiter position by 1
#set ($lenPage = $paramPageToInclude.length())
#set ($contentTitle = $paramPageToInclude.substring($delPos, $lenPage))
#end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Appreciate both of these posts from @Shawn Wilson and @Radek Janata. Amazing the hoops needed to pull out those array elements. I was hoping to use either of these, but no good:
#set ($spaceKey = $paramPageToInclude.split(":")[0])
#set ($pageArray = $paramPageToInclude.split(":"))
#set ($spaceKey = $pageArray[0])
I'm fairly new to custom macro writing, documentation in general seems to be light. Thanks for your posts, they helped me get past a block today.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What exactly do the $paramip look like when you select a "foriegn page"? You may want to add a debug help in the macro to just display the contents of that variable to see what it is returning. Maybe the space key infor is prepended?
I haven't done this type of page navigation before. As your macro is now, it lets a user search and find a page in any space?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried that. $paramip contains only the page name, no space key. The insert-macro-dialog allows an auto-complete search over the complete confluence wiki, same as for the original include page macro (by defining type=confluence-content).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then you are forced to have the user select the space key so that you have that info. Not sure how you trap invalid combinations.
There maybe a way to extract the key data from the page id with a java method. Maybe this will give you enough hints:
https://gist.github.com/chids/870528
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
These solutions take you to the homepage instead of the direct page. Is there a way to go directly to the page instead of the homepage?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.
Register today!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.