ninja
ninja copied to clipboard
can not configure the freemarker template path to local disk path.
I want to read freemarker templates on my local disk , because some times I don't want to rebuild and restart my site.
@Singleton public class FreemarkerConfiguration extends Configuration { public FreemarkerConfiguration() { try { this.setDirectoryForTemplateLoading(new File("C:\Developement\views")); } catch (Exception e) { e.printStackTrace(); }
}
} and bind(Configuration.class).to(FreemarkerConfiguration.class);
it does not work.
That's currently a not supported use case. But why do you want to do that? Ninja automatically picks up changes inside the view folders without restarting anything...
Hi.
You can achieve this by modifying the Freemarker configuration in your Ninja application class. This way:
public class Ninja extends NinjaDefault {
@Inject
Logger logger;
@Inject
TemplateEngineFreemarker templateEngineFreemarker;
@Override
public void onFrameworkStart() {
super.onFrameworkStart();
try {
templateEngineFreemarker.getConfiguration().setDirectoryForTemplateLoading(new File("/Volumes/USBKEY/work"));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
I just tested it and it works... But don't forget, in the directory, to respect the file structure of ninja ("/views/ControllerName/methodName.ftl.html") or to name explicitly your templates when calling render() methods.
Hi,
If I want to using setServletContextForTemplateLoading(ServletContext, String) method to load the template location. How could I get the ServletContext in Ninja?