Search in sources :

Example 41 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project java-docs-samples by GoogleCloudPlatform.

the class GaeInfoServlet method init.

@Override
public void init() {
    // Setup ThymeLeaf
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(this.getServletContext());
    templateResolver.setPrefix("/WEB-INF/templates/");
    templateResolver.setSuffix(".html");
    // TTL=20m
    templateResolver.setCacheTTLMs(Long.valueOf(1200000L));
    // Cache is set to true by default. Set to false if you want templates to
    // be automatically updated when modified.
    templateResolver.setCacheable(true);
    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine) ServletContextTemplateResolver(org.thymeleaf.templateresolver.ServletContextTemplateResolver)

Example 42 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project stdlib by petergeneric.

the class GuiceCoreTemplater method createEngine.

private static TemplateEngine createEngine() {
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode("HTML5");
    resolver.setCacheTTLMs(60 * 1000L);
    resolver.setCacheable(true);
    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine)

Example 43 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project stdlib by petergeneric.

the class GuiceCoreTemplater method getOrCreateEngine.

private TemplateEngine getOrCreateEngine() {
    TemplateEngine engine = this.engine.get();
    // Lazy-create the engine
    if (engine == null) {
        // Build and cache a new templater (previous instance must have been garbage collected)
        engine = createEngine();
        this.engine = new WeakReference<>(engine);
    }
    return engine;
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine)

Example 44 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project stdlib by petergeneric.

the class ThymeleafModule method getTemplateEngine.

@Provides
@Singleton
public TemplateEngine getTemplateEngine(ITemplateResolver resolver) {
    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 45 with TemplateEngine

use of org.thymeleaf.TemplateEngine in project ff4j by ff4j.

the class FF4jServlet method initializeTemplateEngine.

/**
 * Initialize Thymeleaf.
 */
private void initializeTemplateEngine() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode("XHTML");
    templateResolver.setPrefix("views/view-");
    templateResolver.setSuffix(".html");
    templateResolver.setCacheTTLMs(3600000L);
    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    templateEngine.addMessageResolver(new CustomMessageResolver());
    LOGGER.info("Thymeleaf has been initialized");
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine) CustomMessageResolver(org.ff4j.web.thymeleaf.CustomMessageResolver)

Aggregations

TemplateEngine (org.thymeleaf.TemplateEngine)49 Context (org.thymeleaf.context.Context)28 Test (org.junit.Test)17 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)13 MockServletContext (org.springframework.mock.web.MockServletContext)11 RequestContext (org.springframework.web.servlet.support.RequestContext)10 Test (org.junit.jupiter.api.Test)7 WebContext (org.thymeleaf.context.WebContext)7 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)6 SpringTemplateEngine (org.thymeleaf.spring6.SpringTemplateEngine)6 ServletContext (jakarta.servlet.ServletContext)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)5 StringTemplateResolver (org.thymeleaf.templateresolver.StringTemplateResolver)5 ServletContextTemplateResolver (org.thymeleaf.templateresolver.ServletContextTemplateResolver)4 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)3 TemplateSpec (org.thymeleaf.TemplateSpec)3 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2