Reputation: 5788
I have an interesting problem. I'm trying to integrate the Rythm template engine into my Spring MVC application, so I wrote a simple view resolver that invokes RythmeEngine
to render files. However, when I try to use @extends(...)
, the engine returns a blank render. I have two template files:
<!DOCTYPE html>
<html>
<head>
<title>Rythm Sandbox</title>
</head>
<body>
<h1>Welcome!</h1>
@render()
</body>
</html>
@extends(layout)
Hello World!
I am invoking RythmEngine
as follows:
RythmEngine eng = RythmEngineFactory.getEngine();
File f = new File(someRootPath + name + ctx.getSuffix());
resp.setContentType("text/html");
eng.render(httpResponse.getWriter(), f, model);
And RythmEngineFactory.getEngine()
returns a singleton RythmEngine
with the following configuration:
Map<String, Object> props = new HashMap<String, Object>();
props.put("engine.mode", "dev");
props.put("home.template.dir", myTemplateRootDirectoryPath);
return new RythmEngine(props);
Here's the problem: without the @extends(layout)
line in rhythm.html, I get a render "Hello World" as expected. However, when I try to extend layout.html, it results in a blank render (i.e., no output at all). I know it's finding the layout.html file, because if I replace @extends(layout)
with something like @extends(layoutGooBlah)
, the error message says "Cannot find extended template by name 'layoutGooBlah'". So I know it's finding my template fine, but why would the output be blank??
Interesting phenomenon: when I change this line:
eng.render(httpResponse.getWriter(), f, model);
To:
String s = eng.render(f, model);
httpResponse.getWriter().write(s);
It works. ??? Why won't it write to a PrintStream
when using @extends
??
Upvotes: 1
Views: 433
Reputation: 14373
The API engine.render(writer, ...) is buggy. See https://github.com/greenlaw110/Rythm/issues/201
BTW, I recommend you use http://github.com/greenlaw110/spring-rythm for your spring MVC application
Upvotes: 1