[stringtemplate-interest] filling a field ($...$) with data that also contains a (part of) a field ($...$test)

Terence Parr parrt at cs.usfca.edu
Mon Feb 1 10:36:49 PST 2010


Seems like doing it twice is the right way because you actually have to templates: one that contains the template pulled in from a database. Unless the outer template is simply a single hole like $thedata$, it seems like you really do need to templates, which means you need to render twice. Of course, you could patch the templates together into one and then call toString once if you want.
T
On Feb 1, 2010, at 2:19 AM, Christophe Vanderhaeghen wrote:

> Hi all,
> 
> I have a template (myTemplate.st) which is filled with data from the database.
> In the database, the fields might also contain stringtemplate-fields ($...$), thus allowing in the database some dynamics as well.
> 
> What I do now is loop twice through the text where the second wave uses the string-result from the first wave. Like this:
> StringTemplateGroup group = new StringTemplateGroup("Templates", Application.StartupPath +"/Templates/");
> StringTemplate template = group.GetInstanceOf("/Module");
> template.SetAttribute(GetData().GetType().Name, GetData()); //Get the data from the database
> string firstWave = template.ToString(); //Fill the fields with the data that came from the database
>  
> //Now do it for a second time so that the dynamic items from the database are formatted also:
> StringTemplate secondWave = new StringTemplate(firstWave);
> secondWave.SetAttribute(GetData().GetType().Name, GetData());
> string x = secondWave.ToString();
> Question: Is there an alternative way to get all fields filled at once so that I don’t have to StringTemplate twice?
> 
> Thanks in advance,
> 
> Christophe
> 
>  
> 
> _______________________________________________
> 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