Reputation: 3000
I am having a problem getting the Template Representation working in Restlet.
I am using the Template Representation because I have 3 pages that are similar apart from thecontent (I.e header, navigation and footer are the same): index.html, services.html, contact.html Using the template representation will be useful because if I need to change the navigation bar or footer then I will only need to do it in one place (template.html)
I have added the FreeMarker jars to my build path and I can get access to the template data.
I am trying something basic to begin with:
@Get
public Representation represent() {
return new TemplateRepresentation("template.html", new Configuration(), MediaType.TEXT_HTML);
}
I expect whatever is in template.html
to show on the browser. but I get the error No template found
in the console
Here is a cut down version of my file structure.
Java Resources
- src
- Application.java
- IndexResource.java (This class contains the template representation to show the index page)
Web Content
- WEB-INF
- template.html
Upvotes: 0
Views: 861
Reputation: 202146
In fact I think that you need to specify an appropriated template loader on the configuration instance. This will allow Freemarker to know where and how to find out templates...
org.restlet.Context context = (...)
Configuration configuration = new Configuration();
ContextTemplateLoader loader1 = new ContextTemplateLoader(context, "file://<DIR1>");
ContextTemplateLoader loader2 = new ContextTemplateLoader(context, "file://<DIR2>");
MultiTemplateLoader loaders = new MultiTemplateLoader(
new TemplateLoader[] { loader1, loader2 });
configuration.setTemplateLoader(loaders);
You can find all supported implementations of the TemplateLoader interface at address: http://freemarker.sourceforge.net/docs/api/freemarker/cache/TemplateLoader.html. I think that the WebappTemplateLoader implementation could be the one you're looking for...
Hope it helps you. Thierry
Upvotes: 1