速度:如何评估/解析“指令/内容”保存在变量中?
我有一个看起来相当微不足道的问题,但我无法解决它。在我的 Velocity-Templates 中,我有一个变量 $contentFormDb
,它已填充了数据库中的内容(在 MVC 应用程序的控制器中)。该变量不仅包含文字字符串,还包含进一步的速度指令(例如 " #set($test = "test) $test"
,请参见下面的示例)。
如果我使用 $contentFromDB< /code> 在我的模板中,Velocity 以“文字方式”将内容打印到我的模板中,例如,如果变量
$contentFromDB
包含字符串 " #set($test = "test"。 ) $test"
(这已在控制器中设置)我将在我的速度模板中使用文字输出 #set($test = "test) $test
而不仅仅是 < 我需要类似 #parse()
指令,
我可以给我的变量 $contentFromDB
,然后它将评估该变量。 >#parse($contentFormDb) 但是 #parse()
只接受要评估/解析的文件。
也许我完全误解了一些东西......但这似乎是如何解决这个问题。对我来说,这是一个标准用例,其中包含来自数据库的内容,然后也需要在模板中进行评估......
非常感谢! 扬
I have problem that seems to be rather trivial but I was not able to solve it. In my Velocity-Templates I have a variable $contentFormDb
that has been populated with Content from the Database (In the Controller of the MVC App). This Variable will not only contain literal Strings but also further Velocity Directives (like " #set($test = "test) $test"
, see example below).
If I use $contentFromDB
in my templates, Velocity prints the contents into my Template in a "Literal way". For example if the Variable $contentFromDB
contains the String " #set($test = "test) $test"
(this has been set in the Controller) I will eny up with the literal output #set($test = "test) $test
in my velocity template rathern just test
.
I need something like the #parse()
directive that I can give my variable $contentFromDB
and that then will evaluate the variable. #parse($contentFormDb)
But #parse()
only accepts files to be evaluated/parsed.
Maybe I am missunderstanding here something completely... But how to solve this problem this seems to me being a standard use-case having content from the DB that then also needs to be evaluated in the template...
Thank you very much!!
Jan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
#evaluate 指令看起来会做你想做的事。
The #evaluate directive looks like it will do what you want.
你可以通过 #parse() 注册 Velocimacros
这在 Velocity 1.6 中成为可能。
you can register Velocimacros via #parse()
This became possible in Velocity 1.6.