[stringtemplate-interest] Cannot get $elseif(condition)$ to work

Terence Parr parrt at cs.usfca.edu
Wed Feb 22 10:04:42 PST 2012


Hiya. which version?  Should work with v3 and v4. 
Ter
On Feb 22, 2012, at 2:37 AM, Crack Babylon wrote:

> Greetings,
> 
> I am currently working on a DSPF to Java transformation. When constructing my *.stg template file I am struggling to find out why my template code is not working and I am not finding relevent answers in Google or the ST website. The error I get is as follows:
> 
> "java.lang.
> IllegalArgumentException: Can't find template elseif.st; context is [dspfScreenMain anonymous if(it.subfile)_subtemplate]"
> 
> I am iterating through a List of objects and each of these objects can be of type SUBFILE, SUBFILE_CONTROL or STANDARD. So to sort these out I need to do an elseif and I cannot get the $elseif$ working.
> 
> My code is as follows:
> 
> $dspfScreen.screenRecords:{
> $if(it.subfile)$
> FOUND SUBFILE - output sub file inner class
> $elseif(it.subfileCtrl)$
> FOUND SUBFILE CONTROL - output subfile control inner class
> $else$
> FOUND STANDARD - output standard record inner class
> $endif$
> 
> With this code I get the error as explained above. If I remove the $elseif(x)$ I have no problem but I really need to test for multiple things and this won't be the only time I need to do it. So I was wondering why I get the error and why is my code wrong?
> 
> I know there are many ways to skin this cat, I could sort these objects in my Java class and iterate through each of the sorted Lists but being able to use the $esleif$ would be handy.
> 
> Cheers for any help and advice you can give :)
> 
> Thanks
> 
> Big Jim
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list