Spring Boot

The jtwig-spring-boot-starter project allows one to easily integrate Jtwig with Spring Boot. Just by adding the dependency to your project, spring-boot will then load JtwigViewResolver.


Default Configuration

If you include jtwig-spring-boot-starter in your project, by default it will set the view resolver with prefix classpath:/templates/, suffix will be set as .twig and the Jtwig default configuration will be used. Note that, jtwig-spring-boot-starter uses jtwig-web which extends the default Jtwig Core configuration, as already mentioned.


Costumize Configuration

It is still possible to customize JtwigViewResolver to define prefix, suffix and also Jtwig Environment. For that JtwigViewResolverConfigurer interface can be extended by @Configuration annotated class. Note that, such class needs to be injected by spring-boot to the application context.

copy
@Configuration
public class JtwigConfig implements JtwigViewResolverConfigurer {
    @Override
    public void configure(JtwigViewResolver viewResolver) {
        viewResolver.setRenderer(new JtwigRenderer(EnvironmentConfigurationBuilder
            .configuration()
                .extensions().add(new MyExtension()).and()
            .build()));
    }

    private static class MyExtension implements Extension {
        @Override
        public void configure(EnvironmentConfigurationBuilder configurationBuilder) {
            // change config
        }
    }
}

The previous example sets the JtwigViewResolver renderer with an extended version of the EnvironmentConfiguration including a dummy Extension. This working example can be found in jtwig-examples.

Integration

Integration of Jtwig Spring Boot in your project will depend on the dependency management mechanism being used. Also, you will need to make sure jcenter is part of your repository list. The most recent version is 5.86.1.RELEASE.


Gradle

copy
repositories {
    jcenter()
}

dependencies {
    compile 'org.jtwig:jtwig-spring-boot-starter:5.86.1.RELEASE'
}

Maven

copy

    
        bintray
        https://jcenter.bintray.com/
    



    
        org.jtwig
        jtwig-spring-boot-stater
        5.86.1.RELEASE