Skip to main content
Skip table of contents

Add include macros to page templates

Sometimes, it is required to dynamically allocate the macro content for template purposes or other reasons (e.g., when documenting many similar things, like micro services). To achieve this, it is necessary to make the macros' parameters externally available. In the following section, we present examples that help you to create these templates.


Use Case: Create Pages from a Template for Micro Services with 'Include Bitbucket Server for Confluence' Macros

Every micro service page should contain 3 'Include Bitbucket Server for Confluence' macros:


How to

1) Create a Page Template 

Refer to the following guide.

2) Create New User Macros

  1. In the administration section go to the user macro section

  2. Create new user macro

  3. Define name and title for the user macro 

  4. Fill in the code in the mandatory template field. The template content depends on what you like to include. The following examples show some possibilities. It is important to define the required parameters so that you can access them via the user macro

Here are code examples to add instances of the Bitbucket file path, Bitbucket branch list and Bitbucket commits macro:

Include Bitbucket file path with User Macro Template Syntax
CODE
## @param repoSlug|type=string|required=true
## @param branchId|type=string|required=true
## @param projectKey|type=string|required=true
## @param filepath|type=string|required=true
## @param showLineNumbers|type=boolean|required=false|default=true
## @param lineStart|type=int|required=false
## @param progLang|type=string|required=true

<ac:structured-macro ac:name="stashincludebyfilepath">
	<ac:parameter ac:name="repoSlug">$paramrepoSlug</ac:parameter>
	<ac:parameter ac:name="branchId">$parambranchId</ac:parameter>
	<ac:parameter ac:name="projectKey">$paramprojectKey</ac:parameter>
	<ac:parameter ac:name="filepath">$paramfilepath</ac:parameter>
	<ac:parameter ac:name="showLineNumbers">$paramshowLineNumbers</ac:parameter>
	<ac:parameter ac:name="lineStart">$paramlineStart</ac:parameter>
	<ac:parameter ac:name="progLang">$paramprogLang</ac:parameter>
</ac:structured-macro>

Then, go to your template. The following definition of Wiki markup makes the rendering of the Include macro possible : 

Try your example with copy/paste:

CODE
{include-bss-filepath-wrapper-macro:repoSlug=include4confluence|branchId=refs/heads/master|projectKey=TEST|filepath=test-files/source/groovy.gsh|lineStart=4|progLang=groovy}

This renders the following output:

Include Bitbucket branch list with User Macro Template Syntax

CODE
## This is an example macro
## @param repoSlug=Name|type=string|required=true
## @param projectKey=Name|type=string|required=true

<ac:structured-macro ac:name="stashbranches">
	<ac:parameter ac:name="repoSlug">$paramrepoSlug</ac:parameter>
	<ac:parameter ac:name="projectKey">$paramprojectKey</ac:parameter>
</ac:structured-macro>

Then, go to your template. The following definition of Wiki markup makes the rendering of the Include macro possible : 

Try your example with copy/paste:

CODE
{include-bss-branches-wrapper-macro:repoSlug=include4confluence|projectKey=TEST}

This renders the following output:

Include Bitbucket commits list with User Macro Template Syntax
CODE
## @param repoSlug:title=Repo Slug|required=true
## @param branchId:title=Branch Id|required=true
## @param projectKey:title=Project Key|required=true

<ac:structured-macro ac:name="stashcommits">
	<ac:parameter ac:name="repoSlug">$paramrepoSlug</ac:parameter>
	<ac:parameter ac:name="branchId">$parambranchId</ac:parameter>   
	<ac:parameter ac:name="projectKey">$paramprojectKey</ac:parameter>
</ac:structured-macro>

Then, go to your template. The following definition of Wiki markup makes the rendering of the Include macro possible : 

Try your example with copy/paste:

CODE
{include-bss-commits-wrapper-macro:repoSlug=include4confluence|branchId=refs/heads/master|projectKey=TEST}

This renders the following output:


References:

User Macro Template Syntax

Allow Macro content inside any other Macro

Wiki Markup 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.