速度:#if,#else和#end之前或之后的空格?

问题描述 投票:0回答:1

我继承了几个使用Velocity代码的项目。 http://velocity.apache.org/

对于那些对Velocity更有经验的人来说,我的问题可能很简单,也许有些天真,但我必须修复代码中处理extra spacesmissing spaces的bug。

#if (${INCOMPLETE_ACCOUNT})Click "Use Now" to confirm your new Acme ID account $!{MM_ID}. You will be asked to create a password if you haven’t already done so. #elseClick below to download or sign into your new products.#end 

这有效吗?我问同事我们是否需要在elseend之前或之后使用空格,但是他们声称他们不知道。有人说,“总是在#end之前放置一个空间。”但是,它们实际上并不遵循该规则。

我发现一些文档解释了文本中的else(如上例所示)应该像这样使用:

#if( $foo == $bar)it's true!#{else}it's not!#end

(见:http://people.apache.org/~henning/velocity/html/ch05s03.html

问题:我在哪里需要空格? #{else}目前是否可以安全使用?有没有一种方法可以推荐?您是如何在代码中使用#if#else和#end的?

java velocity
1个回答
1
投票

你在速度上不需要spaces

Velocity的行为是吞噬多余的空白。

#set($foo=["$10 and ","a pie"])#foreach($a in $foo)$a#end

有时您无法添加空格,因为您渲染的文件对空格不容忍。

关于使用#{else}在else之后写文本,您可以更改为使用之后的速度注释,如mailing list所示:

#if( $foo == $bar)it's true!#else#**#it's not!#end
© www.soinside.com 2019 - 2024. All rights reserved.