Use of nvelocity.
First: Download a NVelocity-0.4.1.zip on http://nvelocity.sourceforge.net/
In the bin directory under it, you can find nvelocity. dll (which will be used in the net project) and introduce it to the project ....
First, introduce the following namespace:
Using Commons. collections;
Using Nvelocity;
Using Nvelocity. app;
Using Nvelocity. context;
Step 1: Creating a velocityengine is to create a velocityengine instance.
Velocityengine velocity =
New Velocityengine (); // you can also use a constructor with parameters for direct instances.
Extendedproperties props =
New Extendedproperties ();
Velocity. INIT (props );
Step 2: creating the template to load the Template File
In this case, the template class is used and the template is loaded using the gettemplate method of velocityengine.
Template template = velocity. gettemplate (@ "Path/to/myfirsttemplate. VM");
Step 3: merging the template integration template
Velocitycontext context =NewVelocitycontext ();
Context. Put ("From","Somewhere");
Context. Put ("","Someone");
Context. Put ("Subject","Welcome to nvelocity");
Context. Put ("Customer",NewCustomer ("John Doe"));
Step 4: Create an IO stream to output the template content. Stringwriter is recommended (because the template is stored as a string)
Stringwriter writer =NewStringwriter ();
Template. Merge (context, writer );
Response. Write (writer. tostring ());
--- Through the above steps, you can easily use the nvelocity template engine technology.
Have you found the final response. Write (writer. tostring ())?