Class URLTemplateLoader

  • All Implemented Interfaces:
    TemplateLoader
    Direct Known Subclasses:
    ClassPathTemplateLoader, FileTemplateLoader, ServletContextTemplateLoader

    public abstract class URLTemplateLoader
    extends AbstractTemplateLoader

    Strategy interface for loading resources (i.e class path or file system resources)

    Templates prefix and suffix

    A TemplateLoader provides two important properties:

    • prefix: useful for setting a default prefix where templates are stored.
    • suffix: useful for setting a default suffix or file extension for your templates. Default is: '.hbs'

    Usage:

     TemplateLoader loader = new ClassPathTemplateLoader();
     loader.setPrefix("/templates");
     loader.setSuffix(".html");
     Handlebars handlebars = new Handlebars(loader);
    
     Template template = handlebars.compile("mytemplate");
    
     System.out.println(template.apply("Handlebars.java"));
     

    The template loader resolve mytemplate to /templates/mytemplate.html and load it.

    Since:
    0.1.0
    • Constructor Detail

      • URLTemplateLoader

        public URLTemplateLoader()
    • Method Detail

      • sourceAt

        public TemplateSource sourceAt​(java.lang.String uri)
                                throws java.io.IOException
        Description copied from interface: TemplateLoader
        Get a template source from location.
        Parameters:
        uri - The location of the template source. Required.
        Returns:
        A new template source.
        Throws:
        java.io.IOException - If the template's source can't be resolved.