Module io.jooby
Package io.jooby

Interface TemplateEngine

All Superinterfaces:
MessageEncoder

public interface TemplateEngine extends MessageEncoder
Template engine renderer. This class renderer instances of ModelAndView objects. Template engine rendering is done by checking view name and supported file extensions().
Since:
2.0.0
Author:
edgar
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default template path.
    static final String
    Name of application property that defines the template path.

    Fields inherited from interface io.jooby.MessageEncoder

    TO_STRING
  • Method Summary

    Modifier and Type
    Method
    Description
    default byte[]
    encode(Context ctx, Object value)
    MessageEncoder a value into a byte array or null if given object isn't supported it.
    default List<String>
    Number of file extensions supported by the template engine.
    static String
    normalizePath(String templatesPath)
    Normalize a template path by removing the leading `/` when present.
    render(Context ctx, ModelAndView modelAndView)
    Render a model and view instance as String.
    default boolean
    supports(ModelAndView modelAndView)
    True if the template engine is able to render the given view.
  • Field Details

  • Method Details

    • render

      String render(Context ctx, ModelAndView modelAndView) throws Exception
      Render a model and view instance as String.
      Parameters:
      ctx - Web context.
      modelAndView - Model and view.
      Returns:
      Rendered template.
      Throws:
      Exception - If something goes wrong.
    • encode

      default byte[] encode(@NonNull Context ctx, @NonNull Object value) throws Exception
      Description copied from interface: MessageEncoder
      MessageEncoder a value into a byte array or null if given object isn't supported it.
      Specified by:
      encode in interface MessageEncoder
      Parameters:
      ctx - Web context.
      value - Value to render.
      Returns:
      Value as byte array or null if given object isn't supported it.
      Throws:
      Exception - If something goes wrong.
    • supports

      default boolean supports(@NonNull ModelAndView modelAndView)
      True if the template engine is able to render the given view. This method checks if the view name matches one of the extensions().
      Parameters:
      modelAndView - View to check.
      Returns:
      True when view is supported.
    • extensions

      @NonNull default List<String> extensions()
      Number of file extensions supported by the template engine. Default is .html.
      Returns:
      Number of file extensions supported by the template engine. Default is .html .
    • normalizePath

      @NonNull static String normalizePath(@NonNull String templatesPath)
      Normalize a template path by removing the leading `/` when present.
      Parameters:
      templatesPath - Template path.
      Returns:
      Normalized path.