简体   繁体   中英

How can I nest Velocity custom directives?

I've created 2 custom directives in Velocity one for internationalization and one for date formatting. They work great on their own, but now I'm to the point where I need to nest one in the other:

#msg('a_resource','TODAY',#date(1234567890900,'date')))!

However this doesn't work as I get the following exception.

org.apache.velocity.exception.ParseErrorException: Invalid arg #2 in directive #msg at dateTemplate[line 1, column 5]

How can I call the #date directive and pass it's value into the other one?

You need to add double quotes around your directive call: "

#msg('a_resource','TODAY',"#date(1234567890900,'date')"))!

Velocity will evaluate anything in double quotes (like variables, methods, and as needed here: directives)

See: https://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html#stringliterals

采用:

#msg('a_resource','TODAY',"#date(1234567890900,'date')"))!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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