StringTemplate remove < > as delimiters
Asked Answered
D

3

7

I am trying to use StringTemplate in a java web app to generate html emails. When trying to enter line breaks, I use \<br\> This does not seem to be working. \<b\> is not working as well. Is there a way to turn off < and > as delimiters so I can test if this is the issue? All over the StringTemplate documentation it says to use $...$ as your delimiters but doesn't say how to not use <...>

Darbie answered 13/12, 2011 at 13:54 Comment(0)
D
7

When creating a group you can set the delimiters by using

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

Where '$' and '$' are your delimiters.

Darbie answered 13/12, 2011 at 14:12 Comment(2)
I still keep getting invalid character '<'. Are you sure it really disable < as delimiter?Penetration
See Dan's answer below. Use STRawGroupDir instead if you don't have ST headers in st files.Kare
W
3

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

delimiters "$", "$"

...or whatever delimiters you would like. More information is at: https://theantlrguy.atlassian.net/wiki/display/ST4/Group+file+syntax

Wyant answered 16/10, 2012 at 15:21 Comment(0)
E
2

Although Lumpy definitely answered the question correctly, he didn't fix the issue that I was having, so I thought I'd add my solution here for future readers.

Even if you make an x.st file in the STGroupDir that you want to load into the program and render at some point, you will have to define a syntax inside that file (just like you would inside a STGroupFile) like so:

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

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

This is inconvenient if you have a lot of quotation marks in your templates, or if you don't want to include the declaration of the template at the top of the file, or if you want to have a really long template. In those cases, you should use a STRawGroupDir. The downside is that there is no central location at the top of your template file naming all the variables that must be passed in.

Entire answered 5/3, 2013 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.