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

User Macro - $baseUrl

Andrew Frayling
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.
February 5, 2012

Hi,

I'm trying to write a user macro which needs to get hold of the base URL of the Confluence installation in order to construct a link to user profiles, but if I construct a URL using $baseUrl, e.g.

<a href="$baseUrl">My Link</a>

the URL that's given to the <a href> attribute is:

http://192.168.1.104:8090/display/TEST/$baseUrl (which 404's as there's no page called "$baseUrl" and it's including the Space in the URL)

when I was expecting:

http://192.168.1.104:8090/

My Server Base URL is set to http://192.168.1.104:8090/ as this is just a local test instance that I'm working on.

If I use:

$action.getGlobalSettings().getBaseUrl()

this gives me what I want (http://192.168.1.104:8090/), but I get warnings in the log files that getBaseUrl is a deprecated method.

What am I doing wrong? Is there something I need to add to my velocity code to make $baseUrl work? Is it a bug (I'm using Confluence 4.1.2 standalone)?

Here's the test code I'm using just to see what $baseUrl and $action.getGlobalSettings().getBaseUrl() are returning:

## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name

## This is an example macro
## @noparams

<h1>Base URL Test</h1>

<p><a href="$baseUrl">Link 1</a></p>

<p><a href="$action.getGlobalSettings().getBaseUrl()">Link 2</a></p>

Thanks,

Andrew.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Oli S
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.
February 5, 2012

do you need the absolute path, or is the relative path ok?

something like this:

<a href="$req.contextPath/~username" >link to the username  profile </a>

Andrew Frayling
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.
February 5, 2012

Cheers Oliver,

<a href="$req.contextPath/display/~username" >link to the username  profile </a>

gives me what I want, but I'm still confused as to what $baseUrl is supposed to do :-)

Thanks,

Andrew.

1 vote
Matthew J. Horn
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.
June 9, 2012
0 votes
Stefan Baader September 27, 2017

I also have the issue that $baseUrl is offered in the description of available objects but doesn't work.
I replace it by a self-made variable

$urlPrefix
#set( $urlPrefix = "$req.getScheme()://$req.getServerName()$req.contextPath/" )

 

0 votes
Fred Bunting January 15, 2015

It doesn't appear as if anybody answered your question. Namely, how does a user macro get the baseUrl of the Confluence instance?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events