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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get URL from page with special chars in page-title within a user macro

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!

1 answer

1 accepted

0 votes
Answer accepted
Davin Studer Community Leader Dec 22, 2020

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(""", '"')

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.4.6
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

26 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you