Macro Guide

Last modified by Normann P. Nielsen on 2014/03/09 17:57

Using Objects

https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity

 Fucntion Code
 Get current page #set ($pageManager=$action.getPageManager())
 
 Get current Space key #set($spacekey=$renderContext.getOriginalContext().getSpaceKey())
 Get page in Space by Pagetitle #set($pageid=$pageManager.getPage($spacekey,"$title").getId())
  

String functions

 Function Code sample
 String Contains (like Instr) 
 Replace #set($title=$parampath.replace("", ""))
#set($title=$title.replace("%20", " "))
#set($title=$title.replace("/", " / "))
  
 String to an Array #set($foo=$MyString.split(":"))
#foreach($line in $foo)
..........
#end

Number Functions

  
  #set($len=$myStringl.length()-$generalUtil.convertToInteger(4))
  
  

Other Functions

  
 Get LabelList #set($labelList=$content.getGlobalLabels($action.getRemoteUser()))
 Does the Page has Labels #if($labelList.size() > 0)

'Macro in Macro (Function/sub)

This is a recursive sample, where a Macro call itself:

#macro ( GetChildren $parent, $curlevel, $maxlevel)

      #GetChildren ($page, $curlevel, $maxlevel)


#end
 
GetChildren ($root, 1, 5)