Class Qute

java.lang.Object
io.quarkus.qute.Qute

public final class Qute extends Object
Provides quick and convenient access to the engine instance stored in a static variable. If a specific engine instance is not set via the setEngine(Engine) method a default engine is created lazily.

Moreover, the convenient fmt() methods that can be used to format messages easily.

 Qute.fmt("Hello {}!", "Quarkus");
 // => Hello Quarkus!

 Qute.fmt("Hello {name} {surname ?: 'Default'}!", Map.of("name", "Martin"));
 // => Hello Martin Default!

 Qute.fmt("<html>{header}</html>").contentType("text/html").data("header", "<h1>Header</h1>").render();
 // <html>&lt;h1&gt;Header&lt;/h1&gt;</html>
 // Note that for a "text/html" template the special chars are replaced with html entities by default.
 
See Also:
  • Constructor Details

    • Qute

      public Qute()
  • Method Details

    • engine

      public static Engine engine()
      If needed, a default engine is created lazily.

      The default engine has in addition to EngineBuilder.addDefaults():

      Returns:
      the engine
      See Also:
    • setEngine

      public static void setEngine(Engine engine)
      Set a specific engine instance.

      Note that the engine should have a Qute.IndexedArgumentsParserHook registered so that the fmt(String, Object...) method works correcly.

      The cache is always cleared when a new engine is set.

      Parameters:
      engine -
      See Also:
    • fmt

      public static String fmt(String template, Map<String,Object> data)
      Parameters:
      template -
      data -
      Returns:
      the rendered template
    • fmt

      public static String fmt(String template, Object... data)
      The data array is accessibe via the data key, e.g. {data[0]} is resolved to the first argument.

      An empty expression {} is a placeholder that is replaced with an index-based array accessor {data[n]} where n is the index of the placeholder. The first placeholder is replace with {data[0]}, the second with {data[1]}, and so on. For example, "Hello {}!" becomes Hello {data[0]}!.

      Parameters:
      template -
      data -
      Returns:
      the rendered template
    • fmt

      public static Qute.Fmt fmt(String template)
      Parameters:
      template -
      Returns:
      a new format object
    • enableCache

      public static void enableCache()
      The template cache will be used by default.
      See Also:
    • disableCache

      public static void disableCache()
      The template cache will not be used by default.
      See Also:
    • clearCache

      public static void clearCache()
      Clears the template cache.