Hi,
we use the following code to get the url auf a page an create a link to it:
## @param Page:title=Page Name|type=confluence-content|required=true|desc=Select a target page
#set ($page = $pageManager.getPage($spaceKey, $paramPage))
#set ($pageUrl = $req.contextPath + "/pages/viewpage.action?pageId=" + $page.id)
This works as expected in most cases. But if the title of the page contains any special character (&,+, ...) no page is found and no pageId gets returned.
I have found an issue, that can be related:
https://jira.atlassian.com/browse/CONFSERVER-11285
Is there a way to get the url of a page with special-chars in title?
Thanks!
Try this. It takes into account pages in other spaces and pages with a ":" in the title. I've not tested every possible special character but it should work with most.
## @param Page:title=Page Name|type=confluence-content|required=true|desc=Select a target page #if( $paramPage && $paramPage != "" ) ########################## ## Find the page ## ########################## #set( $parts = $paramPage.split(":") ) #set( $i = 0 ) #set( $len = 0 ) #set( $key = "" ) #set( $name = "" ) ##Having trouble finding out the length/size of $parts ... brute force it #foreach( $part in $parts ) #set( $len = $len + 1 ) #end #if ( $len == 1 ) #set( $key = $content.spaceKey ) #set( $name = $paramPage ) #else #foreach( $part in $parts ) #if( $i == 0 ) #set( $key = $part ) #else #if( $i == 1 ) #set( $name = $part ) #else #set( $name = $name + ":" + $part ) #end #end #set( $i = $i + 1 ) #end #end #set( $name = $name.replace("&", "&") ) #set( $name = $name.replace(""", '"') ) #set( $page = $pageManager.getPage($key, $name) ) #set( $pageUrl = $req.contextPath + "/pages/viewpage.action?pageId=" + $page.id ) #end
Thank you, that helps. I needed this one, especially:
#set( $name = $name.replace("&", "&") ) #set( $name = $name.replace(""", '"')
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.