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:
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.
Community moderators have prevented the ability to post new answers.
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>
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This page describes the baseUrl:
https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/" )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It doesn't appear as if anybody answered your question. Namely, how does a user macro get the baseUrl of the Confluence instance?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.