David Marko
David Marko

Reputation: 2519

Using XPages with Freemarker help needed

I would like to use Freemarker template engine in my XPages app but cant get it to work in XPages environment. The problem I have is related to template path which I don't know how to setup correctly. Freemarker simply assumes that templates resides somewhere on file system. I put my template file into the same directory as related java class exists. The path to such file is something like this xspnsf://server:0/xpages_tests.nsf/WEB-INF/classes/tcl/ which doesn't work for me. Is there anyone having experience with this? I simply need directory path to nsf that is accepted by File() constructor. This virtual xspnsf://.... is not understandable for java File object.

Here is the template path code for Freemarker:

Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("??????"));
Template temp = cfg.getTemplate("tmp.ftl");

Upvotes: 1

Views: 130

Answers (2)

ddekany
ddekany

Reputation: 31132

Since you are storing the templates together with the classes (if I understand well), can't you use cfg.setClassForTemplateLoading(SomeClassFromThere.class, "/com/example/yourapplication/templates")?

Upvotes: 1

W_K
W_K

Reputation: 868

Try to use Velocity (http://velocity.apache.org/) instead. It allows You to create custom resources loaders which can easily load templates from any place (for example from documents from notes db).

I have seen it used many times in different xpage projects and it works great.

Upvotes: 0

Related Questions