Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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?
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.