pebble
pebble copied to clipboard
In-memory templates
#228 didn't really get an answer, and I think may also be outdated now. Is there a way to load templates from memory? Not all production uses require inheritance and other features, and writing a template to disk just to load it is a hack at best.
I think getLiteralTemplate(String templateName) might be it but the parameter is templateName with no way to pass in the template body, and the only addition to the description from getTemplate is using a StringLoader which I couldn't make heads or tails of.
getLiteralTemplate is indeed what you are after. It uses whatever string you pass to it as the template
Okay, thanks! Perhaps the documentation could be expanded to make this clear.
StringLoader is heavily used in unit tests, for example: https://github.com/PebbleTemplates/pebble/blob/2634c1c7c1664e1b4d946bcc463cd1ca84d5f252/pebble/src/test/java/com/mitchellbosecke/pebble/TernaryExpressionTest.java#L32-L37
If you configure your PebbleEngine to use a StringLoader, then you simply need to call pebble.getTemplate("Hello, {{who | capitalize}}").