Class PebbleTemplateImpl
java.lang.Object
io.pebbletemplates.pebble.template.PebbleTemplateImpl
- All Implemented Interfaces:
PebbleTemplate
The actual implementation of a PebbleTemplate
-
Constructor Summary
ConstructorsConstructorDescriptionPebbleTemplateImpl(PebbleEngine engine, RenderableNode root, String name) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidblock(Writer writer, EvaluationContextImpl context, String blockName, boolean ignoreOverriden) A typical block declaration will use this method which evaluates the block using the regular user-provided writer.voidembedTemplate(int lineNo, Writer writer, EvaluationContextImpl context, String name, Map<?, ?> additionalVariables, List<BlockNode> overriddenBlocks) Embed a template withnameinto this template and override its child blocks.voidEvaluate the template without any provided variables.voidEvaluate the template with a particular locale but without any provided variables.voidEvaluate the template with a set of variables and the default locale provided by thePebbleEnginevoidEvaluate the template with a particular locale and a set of variables.voidevaluateBlock(String blockName, Writer writer) Evaluate the template but only render the contents of a specific block.voidevaluateBlock(String blockName, Writer writer, Locale locale) Evaluate the template but only render the contents of a specific block.voidEvaluate the template but only render the contents of a specific block.voidEvaluate the template but only render the contents of a specific block.getName()Returns the template namegetNamedImportedTemplate(EvaluationContextImpl context, String alias) Returns a named template.booleanChecks if a block existsbooleanChecks if a macro existsvoidImports named macros from specified template.voidimportNamedTemplate(EvaluationContextImpl context, String name, String alias) Imports a named template.voidimportTemplate(EvaluationContextImpl context, String name) Imports a template.voidincludeTemplate(Writer writer, EvaluationContextImpl context, String name, Map<?, ?> additionalVariables) Includes a template withnameinto this template.macro(EvaluationContextImpl context, String macroName, ArgumentsNode args, boolean ignoreOverriden, int lineNumber) Invokes a macrovoidregisterBlock(Block block) Registers a block.voidregisterMacro(Macro macro) Registers a macrovoidregisterMacro(String alias, Macro macro) Registers a macro with aliasresolveRelativePath(String relativePath) This method resolves the given relative path based on this template file path.voidsetParent(EvaluationContextImpl context, String parentName)
-
Constructor Details
-
PebbleTemplateImpl
Constructor- Parameters:
engine- The pebble engine used to construct this templateroot- The root not to evaluatename- The name of the template
-
-
Method Details
-
evaluate
Description copied from interface:PebbleTemplateEvaluate the template without any provided variables. This will use the default locale provided by thePebbleEngine.- Specified by:
evaluatein interfacePebbleTemplate- Parameters:
writer- The results of the evaluation are written to this writer.- Throws:
IOException- An IO exception during the evaluation
-
evaluate
Description copied from interface:PebbleTemplateEvaluate the template with a particular locale but without any provided variables.- Specified by:
evaluatein interfacePebbleTemplate- Parameters:
writer- The results of the evaluation are written to this writer.locale- The locale used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
evaluate
Description copied from interface:PebbleTemplateEvaluate the template with a set of variables and the default locale provided by thePebbleEngine- Specified by:
evaluatein interfacePebbleTemplate- Parameters:
writer- The results of the evaluation are written to this writer.map- The variables used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
evaluate
Description copied from interface:PebbleTemplateEvaluate the template with a particular locale and a set of variables.- Specified by:
evaluatein interfacePebbleTemplate- Parameters:
writer- The results of the evaluation are written to this writer.map- The variables used during the evaluation of the template.locale- The locale used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
evaluateBlock
Description copied from interface:PebbleTemplateEvaluate the template but only render the contents of a specific block.- Specified by:
evaluateBlockin interfacePebbleTemplate- Parameters:
blockName- The name of the template block to return.writer- The results of the evaluation are written to this writer.- Throws:
IOException- An IO exception during the evaluation
-
evaluateBlock
Description copied from interface:PebbleTemplateEvaluate the template but only render the contents of a specific block.- Specified by:
evaluateBlockin interfacePebbleTemplate- Parameters:
blockName- The name of the template block to return.writer- The results of the evaluation are written to this writer.locale- The locale used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
evaluateBlock
public void evaluateBlock(String blockName, Writer writer, Map<String, Object> map) throws IOExceptionDescription copied from interface:PebbleTemplateEvaluate the template but only render the contents of a specific block.- Specified by:
evaluateBlockin interfacePebbleTemplate- Parameters:
blockName- The name of the template block to return.writer- The results of the evaluation are written to this writer.map- The variables used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
evaluateBlock
public void evaluateBlock(String blockName, Writer writer, Map<String, Object> map, Locale locale) throws IOExceptionDescription copied from interface:PebbleTemplateEvaluate the template but only render the contents of a specific block.- Specified by:
evaluateBlockin interfacePebbleTemplate- Parameters:
blockName- The name of the template block to return.writer- The results of the evaluation are written to this writer.map- The variables used during the evaluation of the template.locale- The locale used during the evaluation of the template.- Throws:
IOException- An IO exception during the evaluation
-
importTemplate
Imports a template.- Parameters:
context- The evaluation contextname- The template name
-
importNamedTemplate
Imports a named template.- Parameters:
context- The evaluation contextname- The template namealias- The template alias
-
importNamedMacrosFromTemplate
Imports named macros from specified template.- Parameters:
name- The template namenamedMacros- named macros
-
getNamedImportedTemplate
Returns a named template.- Parameters:
context- The evaluation contextalias- The template alias
-
includeTemplate
public void includeTemplate(Writer writer, EvaluationContextImpl context, String name, Map<?, ?> additionalVariables) throws IOExceptionIncludes a template withnameinto this template.- Parameters:
writer- the writer to which the output should be written to.context- the context within which the template is rendered in.name- the name of the template to include.additionalVariables- the map with additional variables provided with the include tag to add within the include tag.- Throws:
IOException- Any error during the loading of the template
-
embedTemplate
public void embedTemplate(int lineNo, Writer writer, EvaluationContextImpl context, String name, Map<?, ?> additionalVariables, List<BlockNode> overriddenBlocks) throws IOExceptionEmbed a template withnameinto this template and override its child blocks. This has the effect of essentially "including" a template (as with the `include` tag), but its blocks may be overridden in the calling template similar to extending a template.- Parameters:
lineNo- the line number of the node being evaluatedwriter- the writer to which the output should be written to.context- the context within which the template is rendered in.name- the name of the template to include.additionalVariables- the map with additional variables provided with the include tag to add within the embed tag.overriddenBlocks- the blocks parsed out of the parent template that should override blocks in the embedded template- Throws:
IOException- Any error during the loading of the template
-
hasMacro
Checks if a macro exists- Parameters:
macroName- The name of the macro- Returns:
- Whether or not the macro exists
-
hasBlock
Checks if a block exists- Parameters:
blockName- The name of the block- Returns:
- Whether or not the block exists
-
resolveRelativePath
This method resolves the given relative path based on this template file path.- Parameters:
relativePath- the path which should be resolved.- Returns:
- the resolved path.
-
registerBlock
Registers a block.- Parameters:
block- The block
-
registerMacro
Registers a macro- Parameters:
macro- The macro
-
registerMacro
Registers a macro with alias- Parameters:
macro- The macro- Throws:
PebbleException- Throws exception if macro already exists with the same name
-
block
public void block(Writer writer, EvaluationContextImpl context, String blockName, boolean ignoreOverriden) throws IOException A typical block declaration will use this method which evaluates the block using the regular user-provided writer.- Parameters:
blockName- The name of the blockcontext- The evaluation contextignoreOverriden- Whether or not to ignore overriden blockswriter- The writer- Throws:
IOException- Thrown from the writer object
-
macro
public SafeString macro(EvaluationContextImpl context, String macroName, ArgumentsNode args, boolean ignoreOverriden, int lineNumber) Invokes a macro- Parameters:
context- The evaluation contextmacroName- The name of the macroargs- The argumentsignoreOverriden- Whether or not to ignore macro definitions in child template- Returns:
- The results of the macro invocation
-
setParent
-
getName
Returns the template name- Specified by:
getNamein interfacePebbleTemplate- Returns:
- The name of the template
-