public abstract class URLTemplateLoader extends AbstractTemplateLoader
Strategy interface for loading resources (i.e class path or file system resources)
A TemplateLoader
provides two important properties:
'.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.
DEFAULT_PREFIX, DEFAULT_SUFFIX
Constructor and Description |
---|
URLTemplateLoader() |
Modifier and Type | Method and Description |
---|---|
protected abstract URL |
getResource(String location)
Get a template resource for the given location.
|
TemplateSource |
sourceAt(String uri)
Get a template source from location.
|
getCharset, getPrefix, getSuffix, normalize, resolve, setCharset, setPrefix, setSuffix
public TemplateSource sourceAt(String uri) throws IOException
TemplateLoader
uri
- The location of the template source. Required.IOException
- If the template's source can't be resolved.protected abstract URL getResource(String location) throws IOException
location
- The location of the template source. Required.IOException
- If the url can't be resolved.Copyright © 2022. All rights reserved.