Is there a way to return the HTML contents of a velocity template that includes all directives and conditions?

Viewed 57
<p>Title</p>

#if (condition)
<p>Some message</p>
#end

My java method looks something like:

**public String getTemplateContents(Context context, String template)** {
   StringWriter w = new StringWriter();
   Template t = Velocity.getTemplate(template);
   template.merge(context, w);
   String s = w.toString();
   w.close();
   return s;
}

Currently, s only returns the output: <p>Title</p>

I would like it to output the whole vm template contents:

<p>Title</p>

#if (condition)
<p>Some message</p>
#end

I have also tried using the mergeTemplate method with no success. Please help.

0 Answers
Related