All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.plugins.spincast-templating-addon.spincast-templating-addon.html Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
{#==========================================
Spincast Templating Addon plugin
==========================================#}
{% extends "../../layout.html" %}

{% block sectionClasses %}plugins plugins-spincast-templating-addon{% endblock %}
{% block meta_title %}Plugins - Spincast Templating Addon{% endblock %}
{% block meta_description %}Spincast Templating Addon plugin{% endblock %}

{% block scripts %}

{% endblock %}

{% block body %}

Overview

The Spincast Templating Addon plugin provides a request context add-on: "ITemplatingRequestContextAddon". This add-on allows your route handlers to easily access templating functionalities. It is mounted as .templating() on the default Spincast request context.

Installation

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-templating-addon</artifactId>
    <version>{{spincastCurrrentVersion}}</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 SpincastTemplatingAddonPluginGuiceModule(IAppRequestContext.class, 
                                                     IAppWebsocketContext.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 SpincastTemplatingAddonPluginGuiceModule(getRequestContextType(), 
                                                             getWebsocketContextType()));
        // other modules...
    }
    
    // ...
}

The request context add-on

The add-on returns a ITemplatingEngine instance. Look at the The ITemplatingEngine interface section of the Spincast Pebble plugin (the default implementation of ITemplatingEngine) for a list of methods available on this object!

Quick example :

{% verbatim %}
public void myHandler(IAppRequestContext context) {

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", "Stromgol");

    String html = context.templating().evaluate("<h1>Hi {{name}}!</h1>", params);
    System.out.println(html); // <h1>Hi Stromgol!</h1>
}
{% endverbatim %}

{% endblock %}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy