我在控制器中有一个处理{{_tl2}}{{/tl2}}
标记的scala方法。
def tl2 = {
new TemplateFunction() {
override def apply(input: String): String = {
util.getLength("tag_2", input)
}
}
}
当mustache包含{{_tl2}}Hi, hello{{/i}}
然而,当我有标签,如{{_tl2}}{{my_sentence}}{{/tl2}}
,它传递"{{my_sentence}}",不展开它。所以我明白我需要在TemplateFunction中扩展{{my_sentence}}
。应用方法。是否有一种方法,我可以接受某种功能在应用,我可以使用"输入"?
编辑:我发现了一个类似的问题和解决方案的胡子。js,但没有为它的java实现。
解决方案是直接使用Guava的new com.google.common.base.Function[String, String]()
而不是TemplateFunction
。
这是更新后的定义
import com.google.common.base.{Function => GFunction}
def tl2 = {
new GFunction[String, String]() {
override def apply(input: String): String = {
util.getLength("tag_2", input)
}
}
}
来源:从https://stackoverflow.com/users/2491266/sam-pullara获得离线答案