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

templates.plugins.spincast-pebble.spincast-pebble.html Maven / Gradle / Ivy

{#==========================================
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 %}

Overview

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 %}

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-pebble</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 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...
    }
    
    // ...
}

The ITemplatingEngine interface

Methods :

  • String evaluate(String content, Map<String, Object> params)
    Evaluates the content, using the given parameters.
    Uses the default Locale.
  • String evaluate(String content, Map<String, Object> params, Locale locale)
    Evaluates the content, using the given parameters.
    Uses the specified Locale.
  • String evaluate(String content, IJsonObject jsonObject)
    Evaluates the content, using the given parameters. specified as a IJsonObject.
    Uses the default Locale.
  • String evaluate(String content, IJsonObject jsonObject, Locale locale)
    Evaluates the content, using the given parameters. specified as a IJsonObject.
    Uses the specified Locale.
  • String fromTemplate(String templatePath, Map<String, Object> params)
    Evaluates a template using the given parameters.
    Uses the default Locale.
  • String fromTemplate(String templatePath, Map<String, Object> params, Locale locale)
    Evaluates a template using the given parameters.
    Uses the specified Locale.
  • String fromTemplate(String templatePath, IJsonObject jsonObject)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the default Locale.
  • String fromTemplate(String templatePath, IJsonObject jsonObject, Locale locale)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the specified Locale.

{% endblock %}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy