You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@velocity.apache.org by Pablo Godoy <pg...@gmail.com> on 2009/03/17 14:57:36 UTC
VTL
Hi all! I'm having troubles to merge a template and its parameters by using
VTL.
I did the next example that I found in the apache site:
Velocity.init();
VelocityContext context = new VelocityContext();
context.put( "name", new String("Velocity") );
Template template = Velocity.getTemplate("mytemplate.vm");
StringWriter sw = new StringWriter();
template.merge( context, sw );
This example, worked ok.
But the problem is that I already have the template contents given by
parameter (I don't need to load the resource from the file system).
What can I do? It's necesary to save the contents into a file, and then load
it doing this?
Velocity.getTemplate("templatePath");
I wouldn't like to do it.
Thanks to all!
Regards!
--
Pablo Godoy
Re: VTL
Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, that's the simplest way. If you run into performance problems
later, you can use the StringResourceLoader to allow you to put
strings into a repository and load templates from there to allow your
app to cache templates and not re-parse them every time.
On Tue, Mar 17, 2009 at 7:14 AM, Pablo Godoy <pg...@gmail.com> wrote:
> I finally found it...
>
> I had to do this:
>
> Velocity.evaluate(context, sw, "mystring", templateContents);
>
> Regards!
>
> 2009/3/17 Pablo Godoy <pg...@gmail.com>
>
>> Hi all! I'm having troubles to merge a template and its parameters by using
>> VTL.
>>
>> I did the next example that I found in the apache site:
>>
>> Velocity.init();
>>
>> VelocityContext context = new VelocityContext();
>>
>> context.put( "name", new String("Velocity") );
>>
>> Template template = Velocity.getTemplate("mytemplate.vm");
>>
>> StringWriter sw = new StringWriter();
>>
>> template.merge( context, sw );
>>
>>
>> This example, worked ok.
>>
>> But the problem is that I already have the template contents given by
>> parameter (I don't need to load the resource from the file system).
>>
>> What can I do? It's necesary to save the contents into a file, and then
>> load it doing this?
>> Velocity.getTemplate("templatePath");
>>
>> I wouldn't like to do it.
>>
>> Thanks to all!
>>
>> Regards!
>>
>> --
>> Pablo Godoy
>>
>
>
>
> --
> Pablo Godoy
>
---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@velocity.apache.org
For additional commands, e-mail: general-help@velocity.apache.org
Re: VTL
Posted by Pablo Godoy <pg...@gmail.com>.
I finally found it...
I had to do this:
Velocity.evaluate(context, sw, "mystring", templateContents);
Regards!
2009/3/17 Pablo Godoy <pg...@gmail.com>
> Hi all! I'm having troubles to merge a template and its parameters by using
> VTL.
>
> I did the next example that I found in the apache site:
>
> Velocity.init();
>
> VelocityContext context = new VelocityContext();
>
> context.put( "name", new String("Velocity") );
>
> Template template = Velocity.getTemplate("mytemplate.vm");
>
> StringWriter sw = new StringWriter();
>
> template.merge( context, sw );
>
>
> This example, worked ok.
>
> But the problem is that I already have the template contents given by
> parameter (I don't need to load the resource from the file system).
>
> What can I do? It's necesary to save the contents into a file, and then
> load it doing this?
> Velocity.getTemplate("templatePath");
>
> I wouldn't like to do it.
>
> Thanks to all!
>
> Regards!
>
> --
> Pablo Godoy
>
--
Pablo Godoy