This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Velocity - Using Loops for Handling lists within variables

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All, I am having an issue with using loops on handling a results list variable if it has one or two results.

Here is what I am trying to accomplish.

I have a results list variable with two results:

Supplemental
2nd of result list text

Result
1st of result list text.
==========================================


If I have a results list variable with one result

Result
1st of result list text

===============================================

Based upon the code I have listed below, this works successfully when I have a variable with two results. However, if I only have one result, the label supplemental will display and no results show. This makes sense as the if statement is looking for anything to where the resultslist variable is greater or equal to 2. The issue I am having is that I can't seem to get this to work per the result of variable with one result. I tried an elseif statement, but the results end up getting duplicated.


<SPAN style="FONT-SIZE: 14pt">Supplemental</Span><BR>



#set ($a = 0)
#foreach ($results in $reportInfo.resultslist)
#set ($a = $a + 1)
#if ($a >= 2)
<BR>
<SPAN style="FONT-SIZE: 14pt">Result</Span>
<BR>
#end
<BR>
$resultslist
<BR>
 
Rancher
Posts: 1041
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can access from the template the size() of the list and build a velocity condition using it.
 
I want my playground back. Here, I'll give you this tiny ad for it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!