And you have a known event ID/Name for each of the 5 Webinars.
So, there is probably a more elegant way, but if it were me, I'd:
The nice thing about this approach is that if you add more webinars, you just need to add them to the master map and everything will keep working without the need for additional if then statements.
This code is untested and I'm sure full of bugs (that @SanfordWhiteman will both point out, and also detail a better way of doing things), but something along these lines:
#set( $viewedWebinarDetails = {} )
#set( $unviewedWebinarDetails = {} )
#set( $allWebinarDetails = {
124365 : {
"id":124365,
"valueViewed":"Congratulations - you watched a webinar about mice",
"valueUnviewed": "Why haven't you watched this webinar about mice"
},
9843524 : {
"id":9843524 ,
"valueViewed":"Congratulations - you watched a webinar about the great wall of china",
"valueUnviewed": "Why haven't you watched this webinar. It talks about dead slaves"
},
742353 : {
"id":742353 ,
"valueViewed":"Congratulations - you watched a webinar about paint drying",
"valueUnviewed": "You know you want to watch this. What could be more exciting"
}
})
#foreach( $viewedWebinar in $oN24Attendee_cList )
#set($aWebinar = allWebinarsDetails[$viewedWebinar.eventid])
#set($dummy = $viewedWebinarsDetails.put[$aWebinar.eventid: {"id":$aWebinar.id, "valueViewed":$aWebinar.valueViewed}])
#end
#foreach ( $aWebinar in allWebinarDetails)
#set($viewedWebinar = viewedWebinar[$viewedWebinar.eventid])
#if( ! $viewedWebinar )
#set($dummy = $unviewedWebinarsDetails.put[$aWebinar.eventid: {"id":$aWebinar.id, "valueUnviewed":$aWebinar.valueUnviewed}])
#end
#foreach ( $aWebinar in viewedWebinarDetails)
$aWebinar.valueViewed
#end
#foreach ( $aWebinar in unviewedWebinarDetails)
$aWebinar.valueUnviewed
#end
This code is untested and I'm sure full of bugs (that @SanfordWhiteman will both point out, and also detail a better way of doing things)
Like the approach but it’s true that it won’t even compile that way.
More like
#set( $viewedWebinars = {} )
#set( $unviewedWebinars = {} )
#set( $allWebinarDisplayContent = {
124365 : {
"outputViewed":"Congratulations - you watched a webinar about mice",
"outputUnviewed": "Why haven't you watched this webinar about mice"
},
9843524 : {
"outputViewed":"Congratulations - you watched a webinar about the great wall of china",
"outputUnviewed": "Why haven't you watched this webinar. It talks about dead slaves"
},
742353 : {
"outputViewed":"Congratulations - you watched a webinar about paint drying",
"outputUnviewed": "You know you want to watch this. What could be more exciting"
}
})
#foreach( $viewedWebinar in $oN24Attendee_cList )
#set($details = $allWebinarDisplayContent[$viewedWebinar.eventid] )
#set($void = $viewedWebinars.put($viewedWebinar.eventid, {"output": $details.outputViewed}) )
#end
#foreach ( $webinar in $allWebinarDisplayContent)
#if( !$viewedWebinars.containsKey($webinar.eventid) )
#set($details = $allWebinarDisplayContent[$webinar.eventid] )
#set($void = $unviewedWebinars.put( $webinar.id, {"output": $details.outputUnviewed}) )
#end
#end
#foreach ( $webinar in $viewedWebinars )
$webinar.output
#end
#foreach ( $webinar in $unviewedWebinars )
$webinar.output
#end
I knew mine wouldn't work as it was, it was hacked together with my slightly janky Velocity skills. I'm slightly astounded it was as close as it was :).
I didn't know about containsKey... that's SUPER handy :), especially as it means the viewedWebinars and unviewedWebinars can just be arrays rather than maps. I'm very happy to have learned about that today.
I notice $void gets chromakeyed differently. Does it have special meaning vs. $dummy (which I used from a quick look on stackoverflow).
Cheers
Jo
$void isn’t special in Velocity, but we have to use the Java highlighter, and void is special in Java.
Speaking of which @Jon_Chen can we get the JavaScript highlighter back, please? It’s giving me a bad vibe to make people highlight JavaScript as Java, when they’re very different.
@Yan_Mak ,
have you tried the solution put forward by @SanfordWhiteman and myself?
FWIW - you can split @SanfordWhiteman's version into three tokens. One that does the set up of the two output lists, and then one token each for outputting the data.