How to link to Space home in User Macro?

This macro lets you enter a page name, and prints "This is the <Page Name> page in the <Space Name> space"

## @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


<br>
This is the
<ac:link>
    <ri:page ri:content-title="$!contentTitle" ri:space-key="$spaceKey"/> $!contentTitle
</ac:link>
page in the
     $spaceManager.getSpace($spaceKey).getName()
space.

The <PageName> line is a link to the page, and it works. The <SpaceName> displays the name of the space correctly. But when I try to make the <SpaceName> line into a link, like this:

<ac:link>
    <ri:page ri:content-title=$spaceManager.getSpace($spaceKey).getName()>
</ac:link>

...it doesn't show the full name. For instance, it says "Testing" instead of the correct name, "Testing Space", and of course the link it creates is dead.

 

 

 

 

1 answer

1 accepted

0 vote
Stephen Deutsch Community Champion Aug 30, 2017

Confluence and Velocity don't have a built in way of linking to a page without showing the page name. Therefore, you have to build the link yourself:

## @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) )

<p> </p>
<p> This is the
<ac:link>
<ri:page ri:content-title="$!contentTitle" ri:space-key="$spaceKey"/>
</ac:link>
page in the
<a href="$linkSpace.homePage.urlPath"> $linkSpace.name </a>
space.
</p>

That works. Thanks!

One question: What's the difference between ".name" (which you used) and ".getname" (which I had used)?

Stephen Deutsch Community Champion Aug 31, 2017

Hi Shawn,

It's exactly the same. Velocity has a name-shortening shortcut built in, so if you have a procedure with no parameters (like .getName()) then you can refer to it without the get and make the first capital letter small (.name) and it will refer to the same thing.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Friday in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

284 views 11 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you