Skip to content

Commit 0794f40

Browse files
committed
string template
1 parent b893844 commit 0794f40

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: StringTemplate
3+
summary: StringTemplate is a Java template engine for generating source code, web pages, emails, or any other formatted text output.
4+
date_published: 2026-01-09T09:49:03+01:00
5+
keywords:template,java
6+
external_url: https://www.stringtemplate.org
7+
---
8+
9+
# [%title]
10+
11+
While reading [Spring AI in Action](https://www.manning.com/books/spring-ai-in-action), I discovered [StringTemplate](https://www.stringtemplate.org).
12+
13+
> StringTemplate is a Java template engine for generating source code, web pages, emails, or any other formatted text output.
14+
> StringTemplate is particularly good at code generators, multiple site skins, and internationalization / localization. StringTemplate also powers ANTLR.
15+
16+
- [Website](https://www.stringtemplate.org)
17+
- [GitHub Repository](https://github.com/antlr/stringtemplate4)
18+
- [IntelliJ Plugin](https://plugins.jetbrains.com/plugin/8041-stringtemplate-v4)
19+
20+
I am thinking of adding support for StringTemplate in [Micronaut Views](https://micronaut-projects.github.io/micronaut-views/latest/guide/).
21+
22+
```java
23+
String template = """
24+
You are a helpful assistant, answering questions about tabletop games.
25+
If you don't know anything about the game or don't know the answer,
26+
say "I don't know".
27+
28+
The game is {game}.
29+
30+
The question is: {question}.""";
31+
String prompt = new ST(template, '{', '}')
32+
.add("game", question.gameTitle())
33+
.add("question", question.question())
34+
.render();
35+
```

0 commit comments

Comments
 (0)