Fork me on GitHub


In package com.mitchellbosecke.pebble

public static class PebbleEngine.Builder extends Object

A builder to configure and construct an instance of a PebbleEngine.


public Builder()

Creates the builder.

  • No parameters


public Builder loader(Loader<?> loader)

Sets the loader used to find templates.

  • Loader<?> loader

    A template loader

public Builder extension(Extension extensions)

Adds an extension, can be safely invoked several times to add different extensions.

  • Extension extensions

    One or more extensions to add

public Builder syntax(Syntax syntax)

Sets the syntax to be used.

  • Syntax syntax

    The syntax to be used

public Builder strictVariables(boolean strictVariables)

Changes the strictVariables setting of the PebbleEngine. The default value of this setting is "false".

The following examples will all print empty strings if strictVariables is false but will throw exceptions if it is true:

{{ nonExistingVariable }} {{ nonExistingVariable.attribute }} {{ nullVariable.attribute }} {{ existingVariable.nullAttribute.attribute }} {{ existingVariable.nonExistingAttribute }} {{ array[-1] }}
  • boolean strictVariables

    Whether or not strict variables is used

public Builder newLineTrimming(boolean enableNewLineTrimming)

Changes the newLineTrimming setting of the PebbleEngine. The default value of this setting is "true".

By default, Pebble will trim a newline that immediately follows a Pebble tag. For example, {}\n{} will have the newline removed.

If newLineTrimming is set to false, then the first newline following a Pebble tag won't be trimmed. All newlines will be preserved

  • boolean enableNewLineTrimming

    Whether or not the newline should be trimmed.

public Builder defaultLocale(Locale defaultLocale)

Sets the Locale passed to all templates constructed by this PebbleEngine.

An individual template can always be given a new locale during evaluation.

  • Locale defaultLocale

    The default locale

public Builder maxRenderedSize(int maxRenderedSize)

Sets the maximum size of the rendered template to protect against macro bombs. See for example If the rendered template exceeds this limit, then a PebbleException is thrown. The default value is -1 and it means unlimited.

  • int maxRenderedSize

    The maximum allowed size of the rendered template.

public Builder executorService(ExecutorService executorService)

Sets the executor service which is required if using one of Pebble's multithreading features such as the "parallel" tag.

  • ExecutorService executorService

    The executor service

public Builder templateCache(PebbleCache<Object, PebbleTemplate> templateCache)

Sets the cache used by the engine to store compiled PebbleTemplate instances.

public Builder tagCache(PebbleCache<CacheKey, Object> tagCache)

Sets the cache used by the "cache" tag.

public Builder autoEscaping(boolean autoEscaping)

Sets whether or not escaping should be performed automatically.

  • boolean autoEscaping

    The auto escaping setting

public Builder allowOverrideCoreOperators(boolean allowOverrideCoreOperators)

Sets whether or not core operators overrides should be allowed.

  • boolean allowOverrideCoreOperators

    Whether or not core operators overrides should be allowed.

public Builder defaultEscapingStrategy(String strategy)

Sets the default escaping strategy of the built-in escaper extension.

  • String strategy

    The name of the default escaping strategy

public Builder addEscapingStrategy(String name, EscapingStrategy strategy)

Adds an escaping strategy to the built-in escaper extension.

  • String name

    The name of the escaping strategy

  • EscapingStrategy strategy

    The strategy implementation

public Builder cacheActive(boolean cacheActive)

Enable/disable all caches, i.e. cache used by the engine to store compiled PebbleTemplate instances and tags cache

  • boolean cacheActive

    toggle to enable/disable all caches

public Builder methodAccessValidator(MethodAccessValidator methodAccessValidator)

Validator that can be used to validate object/method access

  • MethodAccessValidator methodAccessValidator

    Validator that can be used to validate object/method access

public Builder literalDecimalTreatedAsInteger(boolean literalDecimalTreatedAsInteger)

Enable/disable treat literal decimal as Integer. Default is disabled, treated as Long.

  • boolean literalDecimalTreatedAsInteger

    toggle to enable/disable literal decimal treated as integer

public Builder literalNumbersAsBigDecimals(boolean literalNumbersAsBigDecimals)

Enable/disable treat literal numbers as BigDecimals. Default is disabled, treated as Long/Double.

  • boolean literalNumbersAsBigDecimals

    toggle to enable/disable literal numbers treated as BigDecimals

public Builder greedyMatchMethod(boolean greedyMatchMethod)

Enable/disable greedy matching mode for finding java method. Default is disabled. If enabled, when can not find perfect method (method name, parameter length and parameter type are all satisfied), reduce the limit of the parameter type, try to find other method which has compatible parameter types.

For example,

 {{ obj.number(2) }} 
the expression can match all of below methods.
   public Long getNumber(Long v) {...}
   public Integer getNumber(Integer v) {...}
   public Short getNumber(Short v) {...}
   public Byte getNumber(Byte v) {...}
  • boolean greedyMatchMethod

    toggle to enable/disable greedy match method

public Builder registerExtensionCustomizer(Function<Extension, ExtensionCustomizer> customizer)

Registers an implementation of ExtensionCustomizer to change runtime-behaviour of standard functionality.

public PebbleEngine build()

Creates the PebbleEngine instance.

  • No parameters