No Parse
FreeMarker is a java based template engine for complex template processing.
This requires the library freemarker-2.3.16.jar to be in classpath.
The following example shows using noparse directive which helps to output content without parsing.
package com.bethecoder.tutorials.freemarker.tests;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class NoParseTest {
/**
* @param args
* @throws IOException
* @throws TemplateException
*/
public static void main ( String [] args ) throws IOException, TemplateException {
//Get template from classpath
Configuration cfg = new Configuration () ;
cfg.setClassForTemplateLoading ( NoParseTest.class, "/" ) ;
Template template = cfg.getTemplate ( "noparse.ftl" ) ;
//Prepare data model
Map<String, Object> dataModel = new HashMap<String, Object> () ;
dataModel.put ( "name" , "Sriram" ) ;
//Merge template and data
OutputStreamWriter output = new OutputStreamWriter ( System.out ) ;
template.process ( dataModel, output ) ;
}
}
It gives the following output,
1. Sriram
2. Sriram
<#list 1..2 as a>
$ {a}. $ {name}
</#list>