alright, i’m back with a fully-tested way to do this, now with more velocity!
what we’re doing here is using the apache velocity .length()
and .substring()
methods wrapped in an if/else statement. i also set the length as a variable in-line so that it only needs to be written one time (this way, if you want to change the max length, you don’t have to worry about accidentally missing it in one of the two spots we need it).
{
"name": "shortenString",
"type": "static",
"attributes": {
"email": {
"attributes": {
"name": "email"
},
"type": "identityAttribute"
},
"value": "#set($length = 60)#if($email.length() > $length)$email.substring(0,$length)#{else}$email#end"
}
}