Wiki source code of Macro Guide
Last modified by Normann P. Nielsen on 2014/03/09 17:57
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{toc/}} |
| 2 | |||
| 3 | = Using Objects = | ||
| 4 | |||
| 5 | [[https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity]] | ||
| 6 | |||
| 7 | |= Fucntion|= Code | ||
| 8 | | Get current page| {{code}} | ||
| 9 | #set ($pageManager=$action.getPageManager()) | ||
| 10 | |||
| 11 | {{/code}} | ||
| 12 | | Get current Space key| {{code}} | ||
| 13 | #set($spacekey=$renderContext.getOriginalContext().getSpaceKey()) | ||
| 14 | {{/code}} | ||
| 15 | | Get page in Space by Pagetitle| {{code}} | ||
| 16 | #set($pageid=$pageManager.getPage($spacekey,"$title").getId()) | ||
| 17 | {{/code}} | ||
| 18 | | | | ||
| 19 | |||
| 20 | = String functions = | ||
| 21 | |||
| 22 | |= Function|= Code sample | ||
| 23 | | String Contains (like Instr)| | ||
| 24 | | Replace| ###set($title=$parampath.replace("//", "")) | ||
| 25 | #set($title=$title.replace("%20", " ")) | ||
| 26 | #set($title=$title.replace("/", " / "))## | ||
| 27 | | | | ||
| 28 | | String to an Array| ###set($foo=$MyString.split(":")) | ||
| 29 | #foreach($line in $foo) | ||
| 30 | .....####..... | ||
| 31 | #end## | ||
| 32 | |||
| 33 | = Number Functions = | ||
| 34 | |||
| 35 | |= |= | ||
| 36 | | | #set($len=$myStringl.length()-$generalUtil.convertToInteger(4)) | ||
| 37 | | | | ||
| 38 | | | | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | = Other Functions = | ||
| 43 | |||
| 44 | |= |= | ||
| 45 | | Get LabelList| #set($labelList=$content.getGlobalLabels($action.getRemoteUser())) | ||
| 46 | | Does the Page has Labels| #if($labelList.size() > 0) | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | = 'Macro in Macro (Function/sub) = | ||
| 51 | |||
| 52 | This is a recursive sample, where a Macro call itself: | ||
| 53 | |||
| 54 | |||
| 55 | {{code}} | ||
| 56 | #macro ( GetChildren $parent, $curlevel, $maxlevel) | ||
| 57 | |||
| 58 | #GetChildren ($page, $curlevel, $maxlevel) | ||
| 59 | |||
| 60 | |||
| 61 | #end | ||
| 62 | |||
| 63 | GetChildren ($root, 1, 5) | ||
| 64 | {{/code}} |