Search code examples
javastringtemplatestringtemplate-4

Is it possible to make a custom renderer for StringTemplate without using STGroup's?


I'm trying to use StringTemplate to be able to parse some configuration file inputs, and was wondering if it was possible to register a renderer without using STGroup.

Example (but the registerRenderer method seems to be missing from the library):

ST myST = new ST("Hello, <thing>!");
myST.add("thing", new Thing());
myST.registerRenderer(Thing.class, new ThingRenderer());
return myST.render();

Solution

  • Actually after posting this, the answer came to me.

    STGroup myGroup = new STGroup();
    myGroup.registerRenderer(Thing.class, new ThingRenderer());
    ST myST = new ST(myGroup, "Hello, <thing>!");
    myST.add("thing", new Thing());
    return myST.render();