{#========================================== Spincast Templating Addon plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins hasBreadCrumb 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

This plugin provides an implementation for the TemplatingRequestContextAddon Request Context add-on : SpincastTemplatingRequestContextAddon. It allows a Route Handler to easily access templating functionalities. It is mounted as .templating() on the default Spincast Request Context.

Make sure you read the section dedicated to the Templating Engine for more information.

Quick Examples

  • Using the .templating() add-on to evaluate a template using some parameters : {% verbatim %}

    public void myHandler(AppRequestContext 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 %}

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>{{spincast.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(AppRequestContext.class, 
                                                     AppWebsocketContext.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...
    }
    
    // ...
}

Javadoc

{% endblock %}