Class 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:
    fmt(String), fmt(String, Map), fmt(String, Object...)
    • Constructor Detail

      • Qute

        public Qute()
    • Method Detail

      • 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
      • clearCache

        public static void clearCache()
        Clears the template cache.