明文 Velocity 模板单行 foreach
我正在使用速度模板为通知系统生成纯文本电子邮件。我有一个“收件人”POJO 列表,其中包含用户 ID 和电子邮件地址。我想迭代这些 POJO 并在一行中输出用户 ID(最终用逗号等分隔符分隔)。我在格式化输出时遇到问题。例如:
For Info: #foreach( $addressee in $info_addressees )$addressee.userId #end
For Action: #foreach( $addressee in $action_addressees )$addressee.userId #end
不幸的是,这不会在每个 foreach 循环后创建一个新行。所以我得到类似的东西:
信息:user1 user2 user3 操作:user4 user 5 user6
我似乎能够在每个 foreach 循环末尾添加新行的唯一方法是添加一些附加字符,例如:
For Info: #foreach( $addressee in $info_addressees )$addressee.userId END #end
For Action: #foreach( $addressee in $action_addressees )$addressee.userId END #end
我尝试使用空格最后,但似乎这些都被吞噬了,因此被忽略了(不是我所期望的)。
这样做的正确方法是什么?可以用宏来完成吗?
模板的输出必须是纯文本(不能像 HTML 那样结构化);并且,格式化必须在模板中完成,而不是在放入模板模型之前完成。
I'm using velocity templates to generated plain-text emails for a notification system. I have a list of "Addressee" POJOs which contain a user ID and email address. I want to iterate over these POJOs and output the user id in one line (and eventually separated by some delimiter such as commas). I'm having problems formatting the output. For instance:
For Info: #foreach( $addressee in $info_addressees )$addressee.userId #end
For Action: #foreach( $addressee in $action_addressees )$addressee.userId #end
Unfortunately this does not create a new line after each foreach loop. So i get something like:
For Info: user1 user2 user3 For Action: user4 user 5 user6
The only way I seem to be able to add a new line at the end of each foreach loop is by adding some additional character(s), such as:
For Info: #foreach( $addressee in $info_addressees )$addressee.userId END #end
For Action: #foreach( $addressee in $action_addressees )$addressee.userId END #end
I tried using whitespace at the end but it seems that these are gobbled and hence ignored (not what I expected).
What's the right way to do this? And could it be done with a macro?
The output from templating must be plaintext (it cannot be structured like HTML); and, the formatting must be done in the template and not in before being put into the template model.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)