简体   繁体   English

如何编写一个没有输入参数的 FreeMarker 模板 function

[英]How to write a FreeMarker template function with no input parameters

Is it possible to write a FTL function with no input parameters?是否可以编写没有输入参数的FTL function

Like in Java where you can write void test() {} , which takes no arguments and returns nothing.就像在 Java 中一样,您可以在其中编写void test() {} ,它不需要 arguments 并且不返回任何内容。

I have read the documentation .我已经阅读了 文档 But could not find much information on this particular topic.但是找不到关于这个特定主题的太多信息。

Not taking any arguments is just like <#function f>...</#function> .不使用任何 arguments 就像<#function f>...</#function>一样。

Not returning a value is also possible by simply not calling <#return someValue> , and reaching </#function> .不返回值也可以通过简单地不调用<#return someValue>并到达</#function>实现。 However, a function that returns nothing is generally a bad idea.但是,不返回任何内容的 function 通常不是一个好主意。 Then it's more likely that what you want is a macro (see the macro directive).那么你想要的更有可能是一个宏(参见macro )。 In FTL functions are about returning a value, while macros are about side-effects (like printing to the output, or launching a rocket).在 FTL 中,函数是关于返回值的,而宏是关于副作用的(比如打印到 output,或者发射火箭)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM