Richard Warburton
Richard Warburton

Reputation: 1472

Using Play Templates Elsewhere

Is it possible to use the templating engine from the Play Framework in other contexts? Ideally I'd like an api of the form:

String result = render("template-file.html",var1,var2);

In some frameworks the templating engine is entirely usable outside of the framework, or even standalone.

Upvotes: 6

Views: 1194

Answers (3)

Jonathan Scher
Jonathan Scher

Reputation: 71

I asked the very same question on Play's mailing list. Answer :

String result = TemplateLoader.load("virtual/path/to/file").render(mapOfParameters);

http://www.playframework.org/documentation/api/1.2.3/play%2Ftemplates%2FTemplateLoader.html

Upvotes: 7

Codemwnci
Codemwnci

Reputation: 54884

Well, the template engine within Play is Groovy, so first off you could take a look if by simply using Groovy is enough for what you want to achieve.

The best place to look is the Groovy Templating system. I would recommend this rather than trying to unpick, or bundling the Play code.

Upvotes: 3

Ricardo
Ricardo

Reputation: 858

I don't know if you can use templating engine outside Play context but you can generate the html page like this :

Map args = new HashMap();
args.put("var1",var1);
...
String html = TemplateLoader.load("contact.html",args).render(); 

Upvotes: 7

Related Questions