Knowledge Walls
John Peter
Pune, Maharashtra, India
How to escape velocity template reserved words or keywords in .vm with Example
9224 Views
Front Slash (\) 
Front Slash(\) symbol is used to escape statements in VTL.

Example
\#include ("input.txt")
EscapeVTLExample
import java.io.StringWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

public class EscapeVTLExample {
    public static void main(String args[]){
        VelocityEngine ve = new VelocityEngine();
        ve.init();
         
        Template t = ve.getTemplate("velocitytemplate.vm");
         
        VelocityContext vc = new VelocityContext();
        StringWriter sw = new StringWriter();
        
        t.merge(vc, sw);
         
        System.out.println(sw);
    }
}
Velocitytemplate.vm 
#include("file.txt")
\#include("file.txt")
Output 
VTL is a Velocity Template Language.
#include("file.txt")
Best Lessons of "Java Apache Velocity Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details