我如何通过Velocity修剪空白 [英] How can I trim whitespace by Velocity
问题描述
我有一个名为render_something的方法,可以创建大量的空格,例如:
I have a method called render_something which can creates a lot of whitespace, for example:
<a href="#">#render_something('xxx')</a>
结果可以是:
<a href="#">
something that generate from redner_something
</a>
实际上我希望它是这样的:
Which actually I want it to be like this:
<a href="#">something that generate from redner_something</a>
velocity有这样的东西吗?
Does velocity has something like this?
#trim(#render_something('xxx'))
推荐答案
我刚刚阅读了有关 Velocity Whitespace Gobbling 的文章一些解决方法,包括按行评论截断的Velocity Whitespace 。
I just read this article on Velocity Whitespace Gobbling which suggests a few work-arounds including Velocity Whitespace Truncated By Line Comment.
这基本上建议通过在每行末尾添加注释来注释掉换行符。它还建议不要缩进宏中的代码以防止出现多余的(我最喜欢的单词之一)空格。
This basically suggests commenting out line breaks by putting comments at the end of each line. It also suggests not indenting the code in your macros to prevent superfluous (one of my favourite words) spaces occurring.
TBH这不是一个很好的解决方案,但可能适合您的需求。只需在宏的每一行末尾加上 ##
,这会让事情变得更好......等等
TBH it's not a great solution but may suit your needs. Simply put ##
at the end of each line in your macro and that will make things a little bit nicer... sort of
这篇关于我如何通过Velocity修剪空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!