I am looking for a way to use a variable in a URL that is calculated upon page request:
Would this best be done with velocity?
I am looking for a way to use a variable in a URL that is calculated upon page request:
Would this best be done with velocity?
Hi,
It’s not hard to do, but there are a few steps:
First of all, you need to get the current user reference. xcontext.getUser()
should work for that, but there is also a script service so I would recommend $services.user.getCurrentUserReference()
.
Then, from the reference, you need to get the corresponding document, which can be done through $xwiki.getDocument()
(You can look at the documentation here).
And finally, from the document, you can get an edit URL from the getURL() method.
All in all, you would end up with the following snippet:
{{velocity}}
#set($profileUrl = $xwiki.getDocument($services.user.getCurrentUserReference()).getURL("edit"))
[[Edit Profile>>path:$profileUrl]]
{{/velocity}}