[stringtemplate-interest] Including templates from other directories

jingzhao.ou jingzhao.ou at gmail.com
Tue Sep 16 15:28:18 PDT 2008


Hi, all,

I am new to StringTemplate. I searched but was unable to find answers
to my question. That is why I am posting here.

What I want to do is very simple. I have a template in directory a:

$body()$

Usually, this will look for another template body.st under directory
a. However, for some reason, I want to put body.st in another
directory b. I don't know how to write Java code to tell
StringTemplate to look for templates in another directory.

I try the following but with no luck: Can any one help me out?

Thanks a lot!
Jingzhao

========================

File stgDir = new File(src, ".stg");
if (stgDir.isDirectory()) {
     System.out.println("Loading StringTemplateGroup: " +
stgDir.getCanonicalPath());
     StringTemplateGroup.loadGroup(stgDir.getCanonicalPath());
}

......

StringTemplate st = new StringTemplate(tpl);
// turn off caching
st.getGroup().setRefreshInterval(refreshInterval);
// add some string manipulation utilities
st.registerRenderer(String.class, new BasicFormatRenderer());

st.setAttribute("T", data);
String result = st.toString();


More information about the stringtemplate-interest mailing list