PebbleTemplates / pebble

Java Template Engine
https://pebbletemplates.io
BSD 3-Clause "New" or "Revised" License
1.1k stars 168 forks source link

Spring Boot Setup unclear / not working #637

Closed AlEscher closed 1 year ago

AlEscher commented 1 year ago

I have gradle project and am using the following dependency: implementation 'io.pebbletemplates:pebble-spring-boot-starter:3.2.0'. I did not change any settings. I have the following project structure:

src
--main
----java
------com.bla.code
----resources
------static
------templates
--------Base.pebble
--------DeliveryCollected.pebble
--------etc...

Afaiu, I should be able to get a template by doing

this.engine = new PebbleEngine.Builder().build();
engine.getTemplate("DeliveryCollected");

According to your documentation this should work out of the box, however I get the error io.pebbletemplates.pebble.error.LoaderException: Could not find template "DeliveryCollected" (?:?)

I am also unsure how I should address the template. In some examples when using HTML, the ending ".html" is specified, other times it isn't. This documentation says the default extension is ".pebble", however your repo says it is ".peb" (both do not work for me).

ebussieres commented 1 year ago

I'll adjust the documentation. Default extension is now .peb

I suggest that you take a look at https://github.com/PebbleTemplates/spring-petclinic for an example

Btw, you should inject the PebbleEngine created by auto configuration instead of creating a new one. If you create a new one, you'll lose all settings and it won't work.

AlEscher commented 1 year ago

Thank you for the quick reply. I already had a look at the project you linked however it didn't help me alot since I wasn't able to find where you are actually getting the templates. However as usual, as soon as I opened this issue I realized that I probably needed to use Spring Bean to create my Engine, i.e. @Autowired instead of creating the engine as I did. That together with changing the extensions fixed my issue.

I think it would be much easier to add small code examples to this page https://pebbletemplates.io/wiki/guide/spring-boot-integration/ as you did in https://pebbletemplates.io/. My problem was that I mixed the two together.

ebussieres commented 1 year ago

Feel free to make a PR to update the documentation if you think something was unclear. All docs are here : https://github.com/PebbleTemplates/pebble/tree/master/docs/src/orchid/resources/wiki