在Velocity模板中调用Macro函数 [英] Calling Macro function in Velocity template

查看:78
本文介绍了在Velocity模板中调用Macro函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何从速度宏调用返回值并将其分配给变量

I am trying to figure out how to return a value from a velocity macro call and assign it to a varaible

我的宏函数看起来像这样.它曾经存在于通用共享宏文件中

my macro function looks something like this. its once in common shared macros files

#macro(getBookListLink, $readingTrackerResult)
   $readingTrackerResult.getBookListLink()
#end

我需要将此宏的结果分配给另一个速度模板文件中的变量

I am need to assign the result of this macro to a variable in another velocity template file

我尝试过类似的事情

#set($book_list_link = #getBookListLink( $readingTrackerResult ))

但是没有用.我尝试使用#,$并且在getBookListLink函数之前不进行任何操作.但没有任何效果.我不能从宏返回吗?我的宏出了点问题?

but did not work. I tried with #,$ and with nothing in front of function getBookListLink. but nothing worked. Can not i return from a macro? something wrong with my macro?

但是,因此,如果我在html文件中分别调用#getBookListLink($ readingTrackerResult).它的工作原理,我可以将结果打印到用户界面.但无法分配给变量.

But, As such if i call #getBookListLink( $readingTrackerResult ) separately in html file. it works and i can print the result to UI. But not able to assign to a variable.

推荐答案

宏不是函数;它们用于渲染输出.但是,如果您不介意丢失类型并以文本形式获取结果...

Macros are not functions; they are for rendering output. However, if you don't mind losing the type and getting the result as text...

#set( $book_list_link = "#getBookListLink( $readingTrackerResult )" )

这篇关于在Velocity模板中调用Macro函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆