我正在使用Quarkus
模板qute
引擎。我需要注入一些动态js
脚本以加载到 HTML 页面上。但是像这样qute
转换js
:
模板文件hello.html
:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>redirect by script</title>
</head>
<body>
<p>Hi {name}!</p>
<script>
{script}
</script>
</body>
</html>
控制器
@RequestScoped
public class Resource {
@Inject
@Location("hello.html")
Template hello;
@Route(path = "/s/:name", methods = HttpMethod.GET)
public Uni<String> rScript(RoutingContext rc) {
String s = "console.log('Hi from script');";
return Uni.createFrom().completionStage(() -> hello
.data("name", rc.request().getParam("name"))
.data("script", s)
.renderAsync());
}
}
如下模板渲染文件和脚本不会在浏览器上运行:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>redirect by script</title>
</head>
<body>
<p>NOT_FOUND!</p>
<script>
console.log('test redirect by script')
</script>
</body>
</html>
如何将脚本数据传递给qute
模板文件?