Forum Discussion
Thanks DougS
We ended up doing this, which seems excessive but worked:
#set ($postUrl = $notification.message.webUi.url) #if ($postUrl.contains('#')) #set ($splitPostUrl = $postUrl.split('#')) #foreach ($part in $splitPostUrl) #if ($velocityCount == 1) #set ($urlPath = $part) #elseif($velocityCount == 2) #set ($urlHash = $part) #end #end <a href="$!{urlPath}?${utmTag}#$!{urlHash}"> #else <a href="${postUrl}?${utmTag}"> #end
This isn't much documentation here: https://velocity.apache.org/engine/1.5/user-guide.html#loops
Unfortunately $arr.get(index) does not seem to work even though Lithium is using Velocity v1.5
Velocity just exposes java objects and so the methods you can call on them are the public methods on that java object.
The .get method they are using in https://velocity.apache.org/engine/1.5/user-guide.html#loops is an example when looping over a Hashtable (which has a public get method). In that article they use this example:
$allProducts.get($key)
$allProducts in that article is a Hashtable, so it has a .get method.
In your case, you use the .split method to split a string into a String array. Arrays don't have a .get method:
#foreach ($part in $splitPostUrl)
You don't need it though, because you have the array element in your loop (the $part variable).
-Doug
Related Content
- 2 years ago
- 2 years ago