Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Sometimes, it is required to dynamically allocate the macro content for template purposes or other re-using reasons (e.g., when documenting many similar things, like micro services). For this, it might be necessary for the user to make the macros' parameters externally available. In the following section, we present an example that helps users creating 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:


Steps

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.

4.a Define a template to include a Bitbucket Server file path with User Macro Template Syntax

## @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:

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


Hint:  

Enter { then a Space and then } to get into the Wiki Markup area


This renders the following output:

4.b Define a template to include a branch list of a Bitbucket Server repository with User Macro Template Syntax

## 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:

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


This renders the following output:

4.c Define a Template to include the latest Commits from a Bitbucket Server project with  User Macro Template Syntax

## @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:

{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 





  • No labels