velocity模板html格式缩进问题

velocity中常常会写出#foreach #if #else #end等语句,
但由于模板文件中html本身就带有缩进,所以最终的缩进,并不符合velocity语句的含义。当主要针对velocity逻辑阅读时,很不方便

没有处理格式代码:

模板代码:

velocity模板html格式缩进问题

模板代码截图


生成html文件截图:

velocity模板html格式缩进问题

#if产生缩进后的截图

解决办法:

“#if#foreach#else#end”这些语法,不用任何缩进。并且行尾加##注释,表示不解析后面空格


velocity模板html格式缩进问题

定格写,末尾加##注释


velocity模板html格式缩进问题

取消缩进后结果


velocity-wiki地址

https://cwiki.apache.org/confluence/display/velocity/VelocityWhitespaceTruncatedByLineComment

解决办法截图

velocity模板html格式缩进问题


分享到:


相關文章: