StringTemplate removes <> as delimiters

I am trying to use StringTemplate in a java web application to generate html emails. When trying to enter line breaks, I use \<br\> This does not seem to work. \<b\> does not work either. Is there a way to disable <and> as delimiters so that I can check if this is a problem? All StringTemplate documentation says to use $ ... $ as delimiters, but doesn't say how not to use <...>

+6
source share
3 answers

When creating a group, you can set the delimiters using

 STGroup group = new STGroupDir("emails", '$','$'); 

Where "$" and "$" are your delimiters.

+6
source

At the top of the template group file (.stg) you can put:

 delimiters "$", "$" 

... or any delimiters you would like. Additional information: https://theantlrguy.atlassian.net/wiki/display/ST4/Group+file+syntax

+2
source

Although Lumpy definitely answered the question correctly, he did not fix the problem that I had, so I thought that I would add my solution for future readers.

Even if you create an x.st file in STGroupDir that you want to load into the program and render at some point, you will need to define the syntax inside this file (the same as inside STGroupFile ) like this:

 x(variables, go, here) ::= "this uses $variables$ such as $go$ and $here$" 

Note that the syntax must have the same name as the file (minus the extension .st , of course).

This is inconvenient if you have a lot of quotation marks in your templates or if you do not want to include a template declaration at the top of the file or want to have a very long template. In these cases, you should use STRawGroupDir . The disadvantage is that there is no central location at the top of the template file, in which all the variables to be transferred are indicated.

+2
source

Source: https://habr.com/ru/post/903689/


All Articles