Package liqp

Class Template

java.lang.Object
liqp.Template

public class Template extends Object
The main class of this library. Use one of its static parse(...) to get a hold of a reference.

Also see: https://github.com/Shopify/liquid

  • Method Details

    • getParseTree

      public org.antlr.v4.runtime.tree.ParseTree getParseTree()
      Returns the root of the parse tree of the parsed input.
      Returns:
      the root of the parse tree of the parsed input.
    • withContextHolder

      public Template withContextHolder(Template.ContextHolder holder)
    • errors

      public List<Exception> errors()
    • render

      public String render(String jsonMap)
      Renders the template.
      Parameters:
      jsonMap - a JSON-map denoting the (possibly nested) variables that can be used in this Template.
      Returns:
      a string denoting the rendered template.
    • renderToObject

      public Object renderToObject(String jsonMap)
    • render

      public String render()
    • renderToObject

      public Object renderToObject()
    • render

      public String render(Inspectable object)
    • renderToObject

      public Object renderToObject(Inspectable object)
    • renderObject

      public String renderObject(Object obj)
      Render the template with given object, treating it same way as Inspectable instance.
    • render

      public String render(String key, Object value, Object... keyValues)
      Renders the template.
      Parameters:
      key - a key
      value - the value belonging to the key
      keyValues - an array denoting key-value pairs where the uneven numbers (even indexes) should be Strings. If the length of this array is uneven, the last key (without the value) gets `null` attached to it. Note that a call to this method with a single String as parameter, will be handled by `render(String jsonMap)` instead.
      Returns:
      a string denoting the rendered template.
    • render

      public String render(boolean convertValueToMap, String key, Object value, Object... keyValues)
    • render

      public String render(Map<String,Object> variables)
      Renders the template.
      Parameters:
      variables - a Map denoting the (possibly nested) variables that can be used in this Template.
      Returns:
      a string denoting the rendered template.
    • renderToObject

      public Object renderToObject(Map<String,Object> variables)
      Renders the template. The returned type is unspecified (as it may be controlled by a custom RenderTransformer), however calling Object.toString() on that object is guaranteed to be equivalent to calling render(Map).
      Parameters:
      variables - a Map denoting the (possibly nested) variables that can be used in this Template.
      Returns:
      an object denoting the rendered template.
    • render

      public String render(Map<String,Object> variables, ExecutorService executorService, boolean shutdown)
    • renderUnguarded

      public String renderUnguarded(Map<String,Object> variables)
      Renders the template without guards provided by protection settings. This method has about 300x times better performance than plain render.
      Parameters:
      variables - a Map denoting the (possibly nested) variables that can be used in this Template.
      Returns:
      a string denoting the rendered template.
    • renderToObjectUnguarded

      public Object renderToObjectUnguarded(Map<String,Object> variables)
      Renders the template without guards provided by protection settings. The returned type is unspecified (as it may be controlled by a custom RenderTransformer), however calling Object.toString() on that object is guaranteed to be equivalent to calling renderToObjectUnguarded(Map).
      Parameters:
      variables - a Map denoting the (possibly nested) variables that can be used in this Template.
      Returns:
      an object denoting the rendered template.
    • renderUnguarded

      public String renderUnguarded(Map<String,Object> variables, TemplateContext parent, boolean doClearThreadLocal)
    • renderToObjectUnguarded

      public Object renderToObjectUnguarded(Map<String,Object> variables, TemplateContext parent, boolean doClearThreadLocal)
    • renderUnguarded

      public String renderUnguarded(TemplateContext parent)
      Renders the template using parent context
      Parameters:
      parent - The parent context.
      Returns:
      a string denoting the rendered template.
    • toStringTree

      public String toStringTree()
      Returns a string representation of the parse tree of the parsed input source.
      Returns:
      a string representation of the parse tree of the parsed input source.