Forum Discussion
I believe you should be able to do something like this:
#set ($splitPath = urlPath.split(",")) #foreach ($path in $splitPath) ${path} #end
-Doug
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
- DougS8 years agoKhoros Oracle
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
- Inactive User4 years ago
ttadej Where is the value of $velocityCount assigned?
- Inactive User4 years ago
ttadej Does your code work? I have tried it in one of our emails and it isn't working as I would expect. Did you change anything in it?
Related Content
- 2 years ago
- 2 years ago