I'm trying to use the confluence-content parameter to generate a link in a macro, but I'm running into a few issues. The main problem is that if the macro is referencing a page in the same space, the space key isn't returned by Confluence. This makes it extremely difficult to make an absolute url from the page name. Am I missing something obvious? I've found several questions related to this issue and most of them utilise a pagemanager javascript object quite cleverly but none of them seem to address the issue of a missing space key.
Thank you.
Hello there Alex!
If you need the Space Key of the Space that you are currently in, you should be able to retrieve it with:
$space.key
This is considering that you are trying this in a User Macro. Further, is the thread you are speaking about this one:
Can I get a space key from a page ID in a user macro?
Further, would it be possible for you to share more details about the code you are writing:
- Is this a user macro?
- Are you trying to interact with Confluence using some kind of external API or language?
Please, do not disclose any sensitive information for everyone can see the content posted in the Community.
Let us know your thoughts!
Hi @Diego, thanks for your reply.
I am writing a User Macro. At the moment it is just using standard velocity.
I have a field in my macro that is of type confluence-content but this just returns the plaintext name of the page when it finds a match from the user input. I want to generate a link from this result so I am using javascript to turn the result from that field into a link, however, if the page input into the confluence-content field is in the same space as the instance of the macro, Confluence does not return the space key, which means I can't build a link from this result. I've considered doing something like counting the amount of colons in the string to figure out if a space key is present but seeing as colons are semantically correct in a page title, this is not a reliable method.
What I need is a reliable method of getting a page name AND space key from the confluence-content field, even in the circumstance described above.
I hope I've explained my problem properly! Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.