StringTemplate remove < > as delimiters

[亡魂溺海] 提交于 2019-12-01 17:37:17

When creating a group you can set the delimiters by using

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

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

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.

timseal

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!