Create Page Examples
Title
If no title is specified within the macro, the user will be prompted to specify a new title at page creation.
CSS class
The Create Page link can be changed to a Button by using the value "aui-button" as the CSS class parameter.
Confluence page will appear as:
Parent page
You do not necessarily need to use the current page as the parent for the newly created page. Variables like $parent can be used which will use the current page’s parent to contain the newly generated pages. Any page within the current space can be specified as the parent:
From page
A page from which the new page will copy content, including attachments and labels. Any page within the current space can be specified as the From Page, except blog posts.
Labels
A comma separated list of labels can be supplied for the labels parameter. The labels parameter accepts variable values like $parenttitle or $pagetitle:
Templates
The Create Page macro becomes powerful when used in conjunction with Confluence templates. This allows you to create a simple link that can be clicked to create a page within a specific location, pre-populated with the template layout.
Using naming conventions
It is possible that you may wish to formalise the names that are generated by the Create Page macro. This can be achieved by using the 'Title Prefix' and 'Title Suffix' parameters to surround the name given by the user with something that helps to categorise the page.
Prefix
The example will create pages which are prefixed by the text 'User Submission' to denote that they have been created by a user interacting with your page.
Postfix
The example will add '(Project Brief)' to the end of the name given by the user.
Ident
The user can specify the title of the macro with the parameter $ident. Using this parameter, Create Page macro will automatically create unique titles for new pages. It is also possible to specify from what index the $ident parameter will start.
Increment
The $increment variable can be used within the title, prefix or suffix parameters. Create Page macro will automatically increment the variable each time a new page is created, even if the title is unique.
In order to reset or set the $increment variable to a certain value, a REST Endpoint can be created using Scriptrunner. Below is an example of how this can be done:
package com.onresolve.scriptrunner.canned.confluence.macros
import com.atlassian.confluence.core.ContentPropertyManager
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
/**
* Resets the Increment variable value to specified value
*
*/
@BaseScript CustomEndpointDelegate delegate
setIncrement(httpMethod: "PUT", groups: ["confluence-administrators"]) { MultivaluedMap queryParams ->
def pageId = queryParams.getFirst("pageId") as Long
def incrementValue = queryParams.getFirst("incrementValue")
def pageManager = ComponentLocator.getComponent(PageManager)
def contentPropertyManager = ComponentLocator.getComponent(ContentPropertyManager)
Page createPage = pageManager.getPage(pageId)
if (!createPage) {
return Response.serverError().entity([error: "This page does not exist"]).build()
}
contentPropertyManager.getStringProperty(createPage, "increment")
contentPropertyManager.setStringProperty(createPage, "increment", incrementValue)
}
For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.
Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.