[stringtemplate-interest] Including templates from other directories

jingzhao.ou jingzhao.ou at gmail.com
Tue Sep 16 17:42:37 PDT 2008


Hi, Terence,

The problem is that the group is not under the sub-directories. :-) We
have a common groups which are to be shared by a number of projects.

Not sure whether $../../a/body()$ works or not. I would appreciate a
more portable solution. That is, the group directory is dynamically
passed in while I simply keep $body()$ in my template file.

Thanks a lot!
Jingzhao

On Tue, Sep 16, 2008 at 5:29 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> well, you can have a group with subdirs...then ref $a/body()$ I believe.
> Ter
> On Sep 16, 2008, at 3:28 PM, jingzhao.ou wrote:
>
>> 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();
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>


More information about the stringtemplate-interest mailing list