Reputation: 2032
I'm using Pebble template engine with Spring Boot 2, and everything works fine until I start using inheritance. The browser shows an empty page, no content is returned at all. And unfortunately the server and Catalina (I'm using Tomcat 8.5) logs show no errors.
In my pom I have the following dependencies:
I have the following application.properties
My parent template (resources/templates/base.html.peb)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head></head>
<body>Template test</body>
</html>
My child template (resources/templates/child.html.peb)
{% extends "base.html.peb" %}
When I remove the inheritance Pebble is working fine, and is including and showing the model, so Pebble does work.
Upvotes: 1
Views: 1082
Reputation: 2409
Pebble Spring Boot Starter resolves the template path by concatenation of the prefix, template name, and suffix:
public class PebbleTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
ResourceLoader resourceLoader) {
if (ClassUtils.isPresent("com.mitchellbosecke.pebble.PebbleEngine", classLoader)) {
String prefix = environment.getProperty("pebble.prefix", PebbleProperties.DEFAULT_PREFIX);
String suffix = environment.getProperty("pebble.suffix", PebbleProperties.DEFAULT_SUFFIX);
return resourceLoader.getResource(ResourceLoader.CLASSPATH_URL_PREFIX + prefix + view + suffix).exists();
} else {
return false;
}
}
}
If the template is specified with the suffix in the 'extends' directive, the suffix will be appended one more time and the template won't be found, something like:
resources/templates/base.html.peb.html.peb
To solve the issue, pebble template name has to be specified without prefix in the 'extends' directive:
{% extends "base" %}
For me, this is a bug. Pebble Spring Boot Starter should be able to detect that base template is specified with or without the suffix.
Upvotes: 1