2

I am using StringTemplate to generate HTML and I would like to be able to combine STGroupFile and STGroupDir such that I have a directory of group files. This way I can include multiple templates in one file but also combine templates from multiple files. It doesn't appear that there is support for this but I thought I would see if maybe I'm overlooking something.

In case you are wondering why I would want to do this, lets look at an example from the StringTemplate docs:

test(name) ::= "$name:bracket()$" // apply bracket template to each name
bracket(x) ::= "[$x$]"            // surround parameter with square brackets

Assume the above is all in one file (test.st) and we are using STGroupDir, it will be unable to resolve the "bracket(x)" template unless it is in a separate file (bracket.st). In this particular instance, bracket is like a local helper which is useful for cleaning up the main template. In this case, you probably don't want bracket to be visible outside of test.st.

However, if you wanted to create a library of simple helper templates, you might want to locate them all in one file and have each of them accessible to templates in other files.

sebagomez
  • 9,501
  • 7
  • 51
  • 89
Pete
  • 41
  • 4

1 Answers1

0

Disclaimer: I'm using StringTemplate in C#

You need to use .stg files with groups of templates. StringTemplate groups can import other templates or groups of templates, and you can create those groups from a file or a directory.

sebagomez
  • 9,501
  • 7
  • 51
  • 89