StringTemplate 删除 < >作为分隔符

发布于 2024-12-20 21:32:46 字数 240 浏览 2 评论 0 原文

我正在尝试在 java web 应用程序中使用 StringTemplate 来生成 html 电子邮件。当尝试输入换行符时,我使用 \ 这似乎不起作用。 \ 也不起作用。有没有办法关闭<和>作为分隔符,这样我可以测试这是否是问题所在?在整个 StringTemplate 文档中,它都说使用 $...$ 作为分隔符,但没有说明如何不使用 <...>

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 <...>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁的新欢旧爱 2024-12-27 21:32:46

创建组时,您可以使用

STGroup group = new STGroupDir("emails", '

“$”和“$”是分隔符来设置分隔符。

,'

“$”和“$”是分隔符来设置分隔符。

);

“$”和“$”是分隔符来设置分隔符。

When creating a group you can set the delimiters by using

STGroup group = new STGroupDir("emails", '

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

,'

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

);

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

饮惑 2024-12-27 21:32:46

在模板组文件 (.stg) 的顶部,您可以放置​​:

delimiters "$", "$"

...或您想要的任何分隔符。更多信息请访问:
https://theantlrguy.atlassian.net/wiki/display/ST4/Group +文件+语法

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

耳根太软 2024-12-27 21:32:46

虽然 Lumpy 肯定正确地回答了这个问题,但他没有解决我遇到的问题,所以我想我应该在这里为未来的读者添加我的解决方案。

即使您在 STGroupDir 中创建了一个 x.st 文件,并且希望将其加载到程序中并在某个时刻进行渲染,您也必须在该文件内定义语法(就像在 STGroupFile 中一样):

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

请注意,语法应与文件具有相同的名称(当然,减去 .st 扩展名)。

如果您的模板中有很多引号,或者您不想在文件顶部包含模板声明,或者您想要一个很长的模板,那么这会很不方便。在这些情况下,您应该使用 STRawGroupDir。缺点是模板文件顶部没有中央位置来命名必须传入的所有变量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文