velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Moshe Sambol <>
Subject RE: Template from String
Date Thu, 15 May 2003 13:30:52 GMT

The reason evaluate(...) isn't always the right solution is that sometimes
you want to load your templates from Strings today, during development /
testing / whatever, but tomorrow you want your product to load templates
from database / jar / etc. without major changes to the code.

Velocity's ability to choose the appropriate Template loader based on
configuration allows code to be written independently of the source of the

That is, as long as you use Template objects and Loaders.  If I write my
code your way, using the evaluate method, and then later decide I want my
templates to come from elsewhere, I have to rewrite code.


> -----Original Message-----
> From: Dave Newton [] 
> Sent: Thursday, May 15, 2003 4:17 PM
> To: Velocity Users List
> Subject: Re: Template from String
> > I have a database of email messages that are to be used as 
> templates with 
> > Velocity. The examples assume templates will be files 
> (template.vm). I will 
> > be getting the templates as java.lang.String objects. Could 
> someone tell me 
> > how to load a template from a String rather than a file?

Velocity.evaluate(velocontext, writer, logstr, stringTemplate)

works for me.

If there's a reason that all the other solutions didn't use this and
talked about loaders and all that I'd _really_ like to know, because
I've been using this method for awhile and it works fine for me.


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message