How to Create a Template in Confluence
Creating a reusable template in Confluence can significantly boost productivity by streamlining your content creation process. Here's a comprehensive guide on how to create and customize templates in Confluence.
Before we dive into the details, ensure you have the 'Create and Edit Pages' permission. If you're a space administrator, you can enable the 'Page Template' macro for your space.
Creating a Basic Template
Starting with the basics, let's create a simple template that others can use when creating new pages.
1. Click on 'Create' in the top navigation bar and select 'Page'.
Define the Template Structure
Begin by adding titles, text, and other content blocks as needed. You can use Confluence's rich text editor to format your content. Don't include any dynamic or unique information that should change with each use of the template.
2. Once you've set up the content, click 'More actions' (three dots) at the top right corner, and select 'Convert to template'. Name your template and hit 'Convert'.
Using and Customizing the Template
Your teammates can now use this template to create new pages. To do so, on the 'Create' dropdown, select 'From template' and choose your template.
1. They can customize the content by editing the text, adding images, or using macros. To change the structure, they can click the 'Edit source' button at the bottom of the edit screen.
Adding Dynamic Content with Text_REST
The 'text/rest' macro allows you to add dynamic content to your templates. This content can be parameters that change with each page created from the template.
To use 'text/rest', you'll need some basic familiarity with REST APIs. Here's how to add a parameter:
Adding a Parameter to Your Template
1. In the template editor, click on 'Insert' in the rich text toolbar, then select 'Other macros'.
2. Choose 'Text REST', and enter the URL and query parameter you want to use. For example, if you want to fetch a list of users, you could use `"/rest/api 쓰지weit/1.0/users?limit=50"`.
Using Parameters in Your Template
1. Now, you can use the parameters in your content. Wrap the parameter name in curly braces, like this: `{username}`.
2. When someone creates a new page from your template, they can fill in the parameter values, and Confluence will fetch the dynamic content from the REST API.
Adding Additional Functionality with Scripting
For more complex use cases, you can use Groovy scripts to add dynamic content to your templates.
1. Insert a 'Script' macro into your template, and write your Groovy code. This code should create the dynamic content you want to include.
Accessing Global and Page Properties
1. You can use the 'currentPage' object to access data from the current page, like labels or attachments. To access global properties, use the helpers provided by the 'currentPage' object.
Running Scripts When a Page is Created
To run a script every time a new page is created from your template, use the 'On Create' trigger. In your script, set the 'trigger' property to 'On Create'.
Finally, remember to keep your templates secure. Ensure only authorized users can access and use your templates. You can do this by managing template permissions at the space level or by using blueprints.