For customizing app dynamics email templates, we have to use velocity template 1.7
I have a health rule named ab-cd-ef-gh. First two part is constant and the last two part is the name of the microservice. I want to display the part after 'ef'. Please note that the length of the health rule is not fixed, meaning the part starting from 'ef' can have 2 part or 3 part or 5 part depending on the name.
I have used split function to split based on the delimiter '-'.
Output variable has all the parts of the health rule.
Now I want to print from 2nd index of the array, ie from 'ef' till the end of the array. To get the size of the array , i used #set ($outputsize=$output.size()), ie is array.size().
How will print the part starting from 'ef' till the end of the array.
The logic I used was as below.
#set ($start=5)
#foreach ($i in [$start..$outputsize])
${arrays.asList($output).get($i)}
But, I am not getting the output. Please help me to get the service name printed.
In VTL, arrays and lists are equivalent. On both of them you can use .get(i)
or [i]
to access the ith element, or call the .size()
method.
So I guess that
#set ($outputsize = $output.size() - 1)
#set ($start=5)
#foreach ($i in [$start..$outputsize])
$output.get($i)
#end
is enough, as would:
#set ($outputsize = $output.size() - 1)
#set ($start=5)
#foreach ($i in [$start..$outputsize])
$output[$i]
#end