在速度模板中使用动态变量 [英] Using Dynamic Variables in Velocity Templates
问题描述
我正在使用速度模板来生成电子邮件模板,在这里我想为每个标签"创建表格,并将各自的值作为表格数据.
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.
我正在传递一个包含标签详细信息的列表标签,包括 tagName,我使用它为每个标签传递相应的列表.(如果 tagName = "test",我将测试表的数据作为 $test 传递)
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)
如图所示,我已将每个表的数据设置为 $arrayobjs,但该表不显示行,因为我认为它不会遍历 $arrayobs.请帮我遍历数据并将数据设置到列中.
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.-虽然我可以打印 $tags[0] 的值, $arrayobjs[0] 不打印值
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
推荐答案
在将近 2 年后,我建议以下答案:-)
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
这篇关于在速度模板中使用动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!