Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a custom directive for Apache Velocity

I am using Apache's Velocity templating engine, and I would like to create a custom Directive. That is, I want to be able to write "#doMyThing()" and have it invoke some java code I wrote in order to generate the text.

I know that I can register a custom directive by adding a line

userdirective=my.package.here.MyDirectiveName

to my velocity.properties file. And I know that I can write such a class by extending the Directive class. What I don't know is how to extend the Directive class -- some sort of documentation for the author of a new Directive. For instance I'd like to know if my getType() method return "BLOCK" or "LINE" and I'd like to know what should my setLocation() method should do?

Is there any documentation out there that is better than just "Use the source, Luke"?

like image 530
mcherm Avatar asked Oct 01 '08 19:10

mcherm


1 Answers

I put together a little article about writing custom velocity directives (and tools). Maybe someone will find it useful.

like image 197
serg Avatar answered Oct 21 '22 20:10

serg