You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Bolinger, Gregg D" <Gr...@intrustbank.com> on 2004/08/02 23:35:48 UTC
Getting String object of compiled template
I have done this before and for the life of me can't find the code nor
can I figure out how I found out. I have a template that I would like
to use for Emailing. To work with the JavaMail API I just need to get a
String back of the template merged with the data. Can someone tell me
how to do this? I searched the archives but didn't come up with
anything.
Thanks.
Gregg
Re: Getting String object of compiled template
Posted by Mike Rettig <mi...@gmail.com>.
I do the exact same thing for email. It's just a couple lines of code.
This should do it...
//import java.io.StringWriter;
// import velocity classes
VelocityEngine eng = new VelocityEngine();
//setup engine
StringWriter writer = new StringWriter();
VelocityContext context = new VelocityContext();
// populate context
eng.mergeTemplate("myTemplate.vm", context, writer);
String result = writer.toString();
On Mon, 2 Aug 2004 16:35:48 -0500, Bolinger, Gregg D
<gr...@intrustbank.com> wrote:
> I have done this before and for the life of me can't find the code nor
> can I figure out how I found out. I have a template that I would like
> to use for Emailing. To work with the JavaMail API I just need to get a
> String back of the template merged with the data. Can someone tell me
> how to do this? I searched the archives but didn't come up with
> anything.
>
> Thanks.
>
>
> Gregg
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org