【问题标题】:Freemarker-Macros: How to use a macro twice?Freemarker-Macros:如何使用宏两次?
【发布时间】:2018-03-21 09:03:26
【问题描述】:

我目前正在处理一些合同,并且我的 freemarker 宏运行良好。但是现在我必须使用相同的宏两次,我得到了报告: Expected a hash, but this evaluates to a number 好像同一个宏不能做同样的事情两次,我目前使用的宏是:

[#macro TeilbetragProzent]
[#assign gesamt = ((verkaufsauftrag.beteiligungGesamt)!"") /]
[#assign nominale = ((nominale.betrag)!"")/]
[#if (gesamt?string)!=""] 
[#assign prozent = ((nominale/gesamt)*100)/]
${(prozent)?string["0.##"]}
[#else]100
[/#if]
[/#macro]

我试着稍微改变一下:

[#macro TeilbetragProzent2]
[#assign gesamt2 = ((verkaufsauftrag.beteiligungGesamt)!"") /]
[#assign nominale2 = ((nominale2.betrag2)!"")/]
[#if (gesamt2?string)!=""] 
[#assign prozent2 = ((nominale2/gesamt2)*100)/]
${(prozent2)?string["0.##"]}
[#else]100
[/#if]
[/#macro]

仍然无法正常工作...我错过了什么吗?

【问题讨论】:

    标签: freemarker


    【解决方案1】:

    而不是宏中的问题,我相信您的问题在于第二个分配指令:[#assign nominale = ((nominale.betrag)!"")/]。您正在尝试将散列变量nominale(可能是数字,基于错误消息)中节点betrag 的值分配给同名变量nominale。如果你把变量名改成什么,我想你会成功的。

    [#macro TeilbetragProzent]
    [#assign gesamt = ((verkaufsauftrag.beteiligungGesamt)!"") /]
    [#assign nom = ((nominale.betrag)!"")/]
    [#if (gesamt?string)!=""] 
    [#assign prozent = ((nom/gesamt)*100)/]
    ${(prozent)?string["0.##"]}
    [#else]100
    [/#if]
    [/#macro]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      相关资源
      最近更新 更多