0

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
Decrypter
  • 2,784
  • 12
  • 38
  • 57
  • Try turning up your logging level to DEBUG or ALL so that you can see what the TemplateRepresentation class is trying to do. There is a very strong likelihood the template.html file is not where TemplateRepresentation expects it to be found, and the log will likely tell you where it's looking. – jamesmortensen May 12 '12 at 21:38

1 Answers1

1

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

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360