Set variable value : Variables « Velocity « Java






Set variable value


import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.tools.generic.IteratorTool;

public class IteratorToolExample {

  public static void main(String[] args) throws Exception {
    Velocity.init();

    Template t = Velocity.getTemplate("./src/iteratorTool.vm");

    VelocityContext ctx = new VelocityContext();
    ctx.put("var", new IteratorTool());

    Writer writer = new StringWriter();
    t.merge(ctx, writer);

    System.out.println(writer);
  }
}
-------------------------------------------------------------------------------------
#set($list = ["A", "B", "C", "D", "E"])

$list

           
       








velocity-Set.zip( 877 k)

Related examples in the same category

1.Reference variable by name
2.Velocity Variable Noise Reference
3.Velocity Variable Quite Reference
4.Define and use variable in Velocity
5.Velocity Variable Add
6.Pass variable into Velocity
7.Use a variable defined in Velocity