public static PebbleEngine getNewEngine() { PebbleEngine engine; try { Loader<?> loader = new ClasspathLoader(); engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build(); } catch (PebbleException e) { e.printStackTrace(); throw new IllegalStateException(e); } return engine; }
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); builder.greedyMatchMethod(this.properties.isGreedyMatchMethod()); return builder.build(); } }
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); builder.greedyMatchMethod(this.properties.isGreedyMatchMethod()); return builder.build(); } }
@Bean public PebbleEngine pebbleEngine() { PebbleEngine.Builder builder = new PebbleEngine.Builder(); builder.loader(this.pebbleLoader); builder.extension(this.pebbleSpringExtension()); if (this.extensions != null && !this.extensions.isEmpty()) { builder.extension(this.extensions.toArray(new Extension[this.extensions.size()])); } if (!this.properties.isCache()) { builder.cacheActive(false); } if (this.properties.getDefaultLocale() != null) { builder.defaultLocale(this.properties.getDefaultLocale()); } builder.strictVariables(this.properties.isStrictVariables()); return builder.build(); } }
public static PebbleEngine getNewEngine() { PebbleEngine engine; try { Loader<?> loader = new ClasspathLoader(); engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build(); } catch (PebbleException e) { e.printStackTrace(); throw new IllegalStateException(e); } return engine; }
.strictVariables(false) .extension(new GlobalVariablesExtension() .set("contextPath", router.getContextPath())
@Override public void renderString(String templateContent, Map<String, Object> model, Writer writer) { String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = getLanguageOrDefault(language); } Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = getLocaleOrDefault(language); } try { PebbleEngine stringEngine = new PebbleEngine.Builder() .loader(new StringLoader()) .strictVariables(engine.isStrictVariables()) .templateCache(null) .build(); PebbleTemplate template = stringEngine.getTemplate(templateContent); template.evaluate(writer, model, locale); writer.flush(); } catch (Exception e) { throw new PippoRuntimeException(e); } }