{#========================================== Spincast Pebble plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins plugins-spincast-pebble{% endblock %} {% block meta_title %}Plugins - Spincast Pebble{% endblock %} {% block meta_description %}Spincast Pebble plugin provides templating functionalities using Pebble.{% endblock %} {% block scripts %} {% endblock %} {% block body %}
The Spincast Pebble provides templating and HTML generation functionalities
using Pebble. It contains an implementation
of the ITemplatingEngine interface.
Most of the time, the ITemplatingEngine interface is used directly from
the request context via the
templating() add-on or via
some dedicated methods on the response() add-on.
For example:
{% verbatim %}
public class AppController {
public void myHandler(IDefaultRequestContext context) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "Stromgol");
// Sends an evaluated template using the "response()" add-on:
context.response().sendHtmlTemplate("/templates/myTemplate.html", params);
// Evaluates some inline content using the "templating()" add-on:
String html = context.templating().evaluate("<h1>Hi {{name}}!</h1>", params);
System.out.println(html); // <h1>Hi Stromgol!</h1>
}
}{% endverbatim %}
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-pebble</artifactId>
<version>{{spincastLatestStableVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastPebblePluginGuiceModule(IAppRequestContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastPebblePluginGuiceModule(getRequestContextType()));
// other modules...
}
// ...
}
ITemplatingEngine interface
String evaluate(String content, Map<String, Object> params)
String evaluate(String content, Map<String, Object> params, Locale locale)
String evaluate(String content, IJsonObject jsonObject)
IJsonObject.
String evaluate(String content, IJsonObject jsonObject, Locale locale)
IJsonObject.
String fromTemplate(String templatePath, Map<String, Object> params)
String fromTemplate(String templatePath, Map<String, Object> params, Locale locale)
String fromTemplate(String templatePath, IJsonObject jsonObject)
IJsonObject.
String fromTemplate(String templatePath, IJsonObject jsonObject, Locale locale)
IJsonObject.