Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Replace text which is displayed to users with a link

Edited

What I am looking to accomplish is to search a page's body for a specific string using RegEx and then replace that text with an HTML link to be rendered by Confluence Cloud. I am currently doing this is in Server with custom JavaScript in the "custom header/footer" section of the admin interface but I am now faced with finding an equivalent solution for the cloud.

My imagination thinks I may be able to use the PageView event in ScriptRunner to manipulate the page body and return a new body to be rendered. I haven't seen any examples of this, is it possible?

1 answer

1 accepted

Hi Matt,

I guess listening to the 'Page Viewed' event would be too much. I would suggest listening to the 'Page Updated' and 'Page Created' events. 

Here's an example PUT request to update a page body in the Confluence cloud.

// Page ID
def id = "20873217"

def content = get("/wiki/rest/api/content/${id}").asObject(Map).body

put("/wiki/rest/api/content/${content.id}")
    .header('Content-Type', 'application/json')
    .body([
        version: [
            number: content.version.number + 1
        ],
        title: content.title,
        type: content.type,
        body: [
            storage: [
                value: 'New Content here',
                representation: 'storage'
            ]
        ]
    ])
    .asObject(Map)

Cheers,
Helmy

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Confluence Cloud

🏠 Say hello to the new Confluence Home!

Hi Atlassian Community, My name is DJ Chung, and I’m a Product Manager on the Confluence Cloud team. Today, I’m excited to share a new and improved version of Home. The new Home helps you ...

43,975 views 33 137
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