You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In above route, Pippo will find a template with name "contact" and will respond with the result of rendering template by the template engine (a String).
76
+
53
77
Don't forget that `locals` variables from a response will be available automatically to all templates for the current request/response cycle.
From the above code snippets you can see that we call the `render` method with the template name as parameter but without extension.
89
+
That means that you can change anytime the template file extension without to change the route handler code.
90
+
Also, you can change the template engine without to change teh route handler code (for Freemarker template engine you supply a template `contact.ftl` file,
91
+
for Pebble template engine you supply a `contact.peb` file, and so on).
92
+
93
+
Each template engine has a default file extension but you can change it if you want.
94
+
For example, `PebbleTemplateEngine` has `peb` as default file extension but you can change it in `html`.
95
+
The customization can be applied by adding the following line in `conf/application.properties`:
96
+
97
+
```properties
98
+
template.extension = html
99
+
```
100
+
65
101
For each template engine we expose its configuration. For example __Freemarker__ works with `freemarker.template.Configuration` and __Jade__ works with `de.neuland.jade4j.JadeConfiguration`.
66
-
In _Application.onInit_ you can create a new instance for a discovered template engine or you can modify its configuration.
102
+
In _Application#onInit_ you can create a new instance for a discovered template engine or you can modify its configuration.
67
103
68
104
```java
69
105
publicclassCrudApplicationextendsApplication {
@@ -104,4 +140,21 @@ public class CrudApplication extends Application {
104
140
}
105
141
```
106
142
143
+
By default, all template engines disable the cache in `dev` and `test` mode (to speed the development - change template and refresh the page in browser)
144
+
and enable the cache in `prod` mode (to improve the performance).
145
+
146
+
Majority of builtin template engine supplied by Pippo, come with useful functions (extensions) that increase the readability of template:
147
+
- webjarsAt
148
+
- publicAt
149
+
- i18n
150
+
Read the documentation page allocated to each template engine for more information. The links to individual pages are presented in the start of this page.
151
+
152
+
If you want to add support for other template engine in your application you must follow below steps:
153
+
- create a new module/project
154
+
- create a class (ex. MyTemplateEngine) that extends `AbstractTemplateEngine` (or implements `TemplateEngine`)
155
+
- mark your template engine class as service using one of the methods below
156
+
- automatically via `@MetaInfServices` annotation (mark your template engine class with this annotation)
157
+
- manually, add file `ro.pippo.core.TemplateEngine` in _src/main/resources/META-INF/services_ folder with your class name that implements
158
+
TemplateEngine as content (for Jade the content file is _ro.pippo.jade.JadeTemplateEngine_).
159
+
107
160
For more information about how to implement a template engine please see _pippo-freemarker_ and _pippo-jade_ modules.
0 commit comments