-
Notifications
You must be signed in to change notification settings - Fork 0
/
if_label.vm
45 lines (43 loc) · 1.77 KB
/
if_label.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Macro title: if-label
## Macro has a body: Yes
## Macro Body processing: Rendered
##
## Developed by: Chris van Hasselt, FHI 360
## Date created: 14/03/2012
## Installed by: Chris van Hasselt, FHI 360
## Updated by: Martin Cleaver, Blended Perspectives
##
## Description:
## This macro looks for the presence of a particular label, passed in as the first
## (unnamed) parameter.
## The unnamed parameter is signed, that is it can be prefixed by a '+' or '-'
## There are not separate actions for + and - . The rules for action are as
## follows:
## 1) If the sign is +, and the label is present, then the body is displayed
## 2) if the sign is -, and the label is NOT present, then the body is displayed.
## This can be used as a crude approval system, so that if the "approved" label is ## present, an approved "badge" is displayed, for example. If no unnamed
## parameter is present, nothing is displayed
## RegEx pattern to look for either a + or - sign, followed by a label.
## @param label:title=Label Required|type=string|desc=label required for body to show|required=true|multiple=true|default=
#set ($myPattern = '[+-]?.*' )
#if ( $paramlabel && $paramlabel.matches( $myPattern ) )
## first determine the label to look for
#if ($paramlabel.startsWith('+') || $paramlabel.startsWith('-') )
#set ($sign = $paramlabel.substring(0,1) )
#set ($pLabel = $paramlabel.substring(1))
#else
#set ($sign = "+")
#set ($pLabel = $paramlabel)
#end
## bodyPrint default is false if +, true if -
#set ( $bodyPrint = ( $sign == '-' ) )
#foreach ( $label in $content.getLabels() )
#if ( ( $label == $pLabel ) )
#set ($bodyPrint = !$bodyPrint)
#end
#end
#end
#if ( $bodyPrint == true )
$body
#end
## NOTE: If the unnamed parameter is not present, nothing happens.