I am getting started with StringTemplate 4 and I am trying to create a template from a simple string stored in a database. I use something like this:
STGroup group = new STGroupString(null, someTemplateString, '$', '$');
ST st = group.getInstanceOf(someTemplateName);
st.add(someAttribute, someValue);
Now everything works fine if I define all or less than the attribute defined for the template someTemplateName
. Now if I try to add an attribute that doesn't exist, I get the following exception:
no such attribute: fake
java.lang.IllegalArgumentException: no such attribute: fake
...
which makes sense. However, it seems like there's no way for me to know beforehand which attributes are defined for the template someTemplateName
. I was expecting to find something like:
bool isDef = st.isDefined(someAttribute);
but there's no such method. Am I correct? Is there any way around this?
st.impl.formalArguments
only gives you the arguments which you define on the template. It does not give you the names of the attributes used. – Barthol