Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to call space home from a macro

ashan August 12, 2013

Dear forum,

In a user macro, the following line gets me the home page of a space:

<a href="$space.getHomePage().getUrlPath()" class="home">

My question is, this returns the URL as /display/<space-key>/<home page title>. But in my company's docs, we have internally added an extra /wiki part to the URLs. So our URLs read as wiki/display/<space-key>/<page title>. As a result, the macro doesn't work. How can I resolve this issue please?

Thanks

4 answers

1 vote
Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 16, 2013

If that doesn't work you could always use:

&lt;a href="$req.contextPath/display/$space.Key/"&gt;

This will cause Confluence to redirect the user to the homepage of the current space.

smaida September 16, 2013

Hey Steve,

Thanks for the prompt help! I'm not sure what's going on, but it seems the issue is that $space isn't parsing. Your latest code works with the exception of just printing out $space.Key in the template.

-Shawn

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 16, 2013

OK, my guess is that you can't use that where you're using it (e.g., in a layout) because when it is being rendered it is 'outside' of the space, as it were. This is the case with a number of other APIs.

Perhaps you could create a separate question on this site with more details about your problem so that it's separate from this one. Be sure to post a link here and I'll be sure to stop by and take a look (I don't want to hijack ashan's question).

smaida September 16, 2013
Nicolas Casel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 1, 2021

Thank you @Steve Goldberg2  ,

Based on your input, I managed to build url for labels

<a id="clickable-label" class="aui-label" href="$req.contextPath/label/$space.key/$label.getName()">$label.getName()</a>

(should it be useful for other people here)

0 votes
smaida September 16, 2013

Hello,

I'm trying to use $space.getHomePage().getUrlPath() inside of a velocity template, but it doesn't seem to be parsing. I'm trying to link to the space home page from a template of a custom theme. Any ideas?

&lt;div id="logo"&gt;
    &lt;h1&gt;&lt;a href="$space.getHomePage().getUrlPath()"&gt;Home&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;&lt;!-- /#logo --&gt;

Thanks!

0 votes
Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 13, 2013

$content.getAncestors().get(0) lets you get the most top page in a space, which is usually the homepage. However, that won't render the URL path - I'm sure you can fiddle with it so that it does.

Alternatively, you could use some jQuery to re-write the URL (but it would be better not to have to do that).

0 votes
ashan August 13, 2013

Any chance of a reply please? :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events