logo © 2014

Application Quick Start

This quick start explains how to include Jtwig in your Java application.

1. Dependencies

Depending on the dependency management mechanism used, adding Jtwig dependencies may differ.

To integrate Jtwig one need to add the org.jtwig:jtwig-core:5.86.0.RELEASE dependency. Another important aspect is to add the jcenter repository as Jtwig bundles are stored in bintray.

Gradle

copy
repositories {
    jcenter()
}

dependencies {
    compile "org.jtwig:jtwig-core:5.86.0.RELEASE"
}

Maven

copy


    
        jcenter
        https://jcenter.bintray.com/
    



    
        org.jtwig
        jtwig-core
        5.86.0.RELEASE
    

Download

If you don't make use of dependency management systems, it is also possible to download the dependencies via bintray.

2. Jtwig Template

An example of a Jtwig template placed in the classpath, with path templates/example.twig.

copy
Hello {{ var }}

3. Java Code

An example of a simple Java app can be seen below.

copy
package org.jtwig.example;

import org.jtwig.JtwigModel;
import org.jtwig.JtwigTemplate;

public class SimpleApp {
    public static void main(String[] args) {
        JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/example.twig");
        JtwigModel model = JtwigModel.newModel().with("var", "World");

        template.render(model, System.out);
    }
}

All the listed code can be found in Jtwig Examples - Gradle Core Simple.