velocity template

Ads

 
 

Share on Google+Share on Google+

ash
velocity template
1 Answer(s)      8 years ago
Posted in : Struts
Ads
View Answers

January 6, 2009 at 4:07 AM


Hi friend,

Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project.


Here is simple code:


import java.io.*;
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;

public class HelloWorld {
public static void main( String[] args ) throws Exception {
VelocityEngine vengine = new VelocityEngine();
vengine.init();
// next, get the Template
Template temp = vengine.getTemplate("helloworld.vm");
//create a context and add data
VelocityContext context = new VelocityContext();
context.put("name", "World");
// now render the template into a StringWriter
StringWriter writer = new StringWriter();
temp.merge(context, writer);
System.out.println(writer.toString() );
}
}

-------------------------------------

Thanks.

Amardeep


Ads









Related Tutorials/Questions & Answers:
velocity template - Struts
velocity template  what is velocity template and how does it work? whats the flow of execution of velocity template? i want an example using velocity template?  Hi friend, Velocity is an open source templating tool
Version of com.bladejava>blade-template-velocity dependency
List of Version of com.bladejava>blade-template-velocity dependency
Advertisements
Maven Dependency blade-template-velocity >> 0.0.1
You should include the dependency code given in this page to add Maven Dependency of com.bladejava >> blade-template-velocity version0.0.1 in your project
Maven Dependency blade-template-velocity >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.bladejava >> blade-template-velocity version0.0.2 in your project
Maven Dependency blade-template-velocity >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of com.bladejava >> blade-template-velocity version0.0.3 in your project
Maven Dependency blade-template-velocity >> 0.0.4
You should include the dependency code given in this page to add Maven Dependency of com.bladejava >> blade-template-velocity version0.0.4 in your project
Maven Dependency blade-template-velocity >> 0.0.6
You should include the dependency code given in this page to add Maven Dependency of com.bladejava >> blade-template-velocity version0.0.6 in your project
XML handling in a template using Velocity
XML handling in a template using Velocity   ... in a velocity template and also shows that use of  macro to wrap HTML tag in velocity  template. The method used in this example 
how to render my htmlstring from java class in velocity template?
how to render my htmlstring from java class in velocity template?  Hi, I have a java class generates html string dynamically based on the logic. I'm...! Ref: I read your article "Use Velocity to generate HTML document". -Chintu
Velocity
; Apache Velocity is template engine developed by apache foundation... applications. In this tutorial you will learn Velocity template with the help... you how to call class method in velocity template.   
Define and use Macro in Velocity
Define and use Macro in Velocity   ... in velocity  template and also shows how to use Iterator in velocity  template...:- Initialize velocity run time engine through method  init(). 2:- Create object
Velocity Macro with Parameters
Velocity Macro with Parameters   ... with parameters in velocity  template. Example given below show you, how to display date and time velocity. The method used in this example 
Velocity Iterator Tool Example
Velocity Iterator Tool Example     ...; template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use foreach loop in velocity
How to use foreach loop in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
What is Velocity?
What is Velocity?       Velocity is a Java-based template engine. It permits... Velocity Template Language (VTL): The Velocity
Show content of .vm file as output using Velocity
Show content of .vm file as output using Velocity  ... content of .vm file using velocity and also shows how to use Iterator in velocity  template. The method used in this example are described below:- 
Version of velocity>velocity dependency
List of Version of velocity>velocity dependency
Use macro to wrap HTML tags in velocity
Use macro to wrap HTML tags in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init
Version of velocity>velocity-dep dependency
List of Version of velocity>velocity-dep dependency
Hibernate Template
Hibernate Template  Define Hibernate Template
Artifacts of velocity
List of Artifacts of velocity maven depenency
XML template
XML template  Hi..... please tell me about What is XML template? Thanks
Version of velocity-tools>velocity-tools dependency
List of Version of velocity-tools>velocity-tools dependency
Version of plexus-velocity>plexus-velocity dependency
List of Version of plexus-velocity>plexus-velocity dependency
Version of velocity-dvsl>velocity-dvsl dependency
List of Version of velocity-dvsl>velocity-dvsl dependency
Velocity with External Properties
for controlling template methods and properties. "runtime.log = velocity_example.log... Velocity with External Properties       This Example shows you how to use Velocity
Use if in velocity
Use if in velocity       This example shows you how to use if statement in velocity. Description of methods used in the example given below.... 1:- Initialize velocity run time
Version of velocity-tools>velocity-tools-view dependency
List of Version of velocity-tools>velocity-tools-view dependency
Version of velocity-tools>velocity-tools-generic dependency
List of Version of velocity-tools>velocity-tools-generic dependency
The benefits of Hibernate Template.
The benefits of Hibernate Template.  What are the benefits of Hibernate Template

Ads

 
Advertisement null

Ads