英文:
Thymeleaf th:each access parameter in loop
问题
我正在尝试在HTML表格中对一个数字进行上标处理,该表格将显示在电子邮件中。
到目前为止,我的代码如下:
<th:block th:each="param, rowStat: ${someList}">
<th style="..." th:utext="#{some.translation(${param}, ${rowStat.count})}">superscript</th>
</th:block>
"someList" 是一个简单的字符串列表,"some.translation" 如下所示:
{0} (moreInfo)<sup>{1}</sup>
我想要实现的效果类似于:
String1 (moreInfo)<sup>1</sup><br>
String2 (moreInfo)<sup>2</sup>
我的问题是Thymeleaf抛出一个异常,说在这个上下文中访问变量"param"是被禁止的。访问"rowStat.count" 正常工作。
如果有一种更简单的方法来显示上标数字,对我来说也可以。
英文:
I am trying to superscript a number in a html-table which will be displayed in an E-Mail.
my code so far is the following:
<th:block th:each="param, rowStat: ${someList}">
<th style="..." th:utext="#{some.translation(${param}, ${rowStat.count})}">superscript</th>
</th:block>
"someList" is a simple list of strings and "some.translation" is the following:
{0} (moreInfo)<sup>{1}</sup>
What I am trying to achieve is something like:
String1 (moreInfo)<sup>1</sup><br>
String2 (moreInfo)<sup>2</sup>
My problem is a thymeleaf exception saying that the access to variable "param" is forbidden in this context. Accessing "rowStat.count" is working fine.
If there is a simpler way to display a superscript number it would also be fine for me.
答案1
得分: 2
您不能使用param
,因为它是Thymeleaf的保留字,用于检索请求参数。尝试将其更改为其他名称:
<th:block th:each="myParam, rowStat: ${someList}">
<th style="..." th:utext="#{some.translation(${myParam}, ${rowStat.count})}">superscript</th>
</th:block>
请参阅Thymeleaf文档中的Request parameters了解更多信息。
param
用于检索请求参数。${param.foo}
是一个String[]
,其中包含foo
请求参数的值,因此通常会使用${param.foo[0]}
来获取第一个值。
英文:
Your use of param
is not allowed, because that is a reserved word for Thymeleaf, for retrieving request parameters. Try changing it to something else:
<th:block th:each="myParam, rowStat: ${someList}">
<th style="..." th:utext="#{some.translation(${myParam}, ${rowStat.count})}">superscript</th>
</th:block>
See also the Thymeleaf documentation here: Request parameters.
> param
: for retrieving request parameters. ${param.foo}
is a String[]
with the values of the foo
request parameter, so ${param.foo[0]}
will normally be used for getting the first value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论