Reputation:
I am using velocity templates to generate email templates and here I want to create tables for each 'tag' with respective values as table data.
I am passing a List tags with details of the tags including tagName, using which I am passing the respective List for each tag. (If tagName = "test", I am passing the data for the test table as $test)
As shown I have set the data of each table to $arrayobjs, but the table does not display the rows as I think it doesnt iterate through the $arrayobs. Please help me iterate through the data and set the data to the coloumns.
P.S.-Although I am able to print the value of $tags[0] , $arrayobjs[0] does not print a value
#set ($d = '$')
#foreach($tag in $tags)
#set ($var = "${d}${tag.tagName}")
#set ($arrayobjs = "#evaluate($var)")
<table style='width:600px; padding-left: 11px; font:Segoe UI;'>
<tr>
<td> <span style='font-size: 17px; font-weight: 400; font-family:Georgia;'>$tag.tagName </span></td>
</tr>
</table>
<br>
<table width=583 style='width:437.5pt; margin-left:8.25pt;border-collapse:collapse;font-family:"Segoe UI",sans-serif;'>
<tr style='vertical-align:top;height:10px;'>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c;'><b>COL1</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=100px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL2</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL3</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL4</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL5</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL6</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
</tr>
#foreach($o in $arrayobjs)
<tr style='vertical-align:top;height:5px;'>
<td width=50px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col1 </span> </p>
</td>
<td width=180px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col2</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col3</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col4</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col5</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col6</span> </p>
</td>
</tr>
#end
</table>
#end
Upvotes: 2
Views: 1583
Reputation: 1302
After almost 2 years I suggest the following answer :-)
#set ($d = '$')
#set ($h = '#')
#foreach($tag in $tags)
#set ( $temp = "${h}set ( ${d}var = ${d}${tag.tagName} )" )
#evaluate($temp)
## html code for table header
#foreach($o in $var)
## table rows
#end
#end
Upvotes: 3