Class: FetchLoader
A template loader that fetches templates using the Fetch API.
This is an async only loader. Expect an error when using this
loader with getSourceSync() and Environment.getTemplateSync().
This loader treats the response body as text that is the template source code. You might need to write a custom loader to handle JSON responses, for example.
Extends
Constructors
new FetchLoader()
new FetchLoader(
baseURL,options):FetchLoader
The FetchLoader constructor. Creates a new FetchLoader.
Parameters
• baseURL: string
The base URL from which to fetch templates from.
• options: FetchLoaderOptions = {}
Loader options. Most of which are passed
through to the Fetch API's Request constructor.
Returns
Overrides
Defined in
src/builtin/loaders/fetch_loader.ts:80
Properties
baseURL
readonlybaseURL:string
Defined in
src/builtin/loaders/fetch_loader.ts:69
Methods
getSource()
getSource(
name):Promise<TemplateSource>
Override getSource to implement a custom loader.
Parameters
• name: string
The name or identifier of a template.
Returns
Promise<TemplateSource>
The source, with any meta data, for the template identified by the given name
Throws
TemplateNotFoundError Thrown if the template can not be found.
Overrides
Defined in
src/builtin/loaders/fetch_loader.ts:92
getSourceSync()
getSourceSync():
TemplateSource
A synchronous version of getSource.
Returns
See
Overrides
Defined in
src/builtin/loaders/fetch_loader.ts:101
load()
load(
name,environment,context?,globals?,loaderContext?):Promise<Template>
Used internally by Environment.getTemplate(). Delegates to getSource.
Parameters
• name: string
• environment: Environment
• context?: RenderContext
• globals?: ContextScope
• loaderContext?
Returns
Promise<Template>
See
getSource. Override load to implement a caching loader.
Inherited from
Defined in
loadSync()
loadSync(
name,environment,context?,globals?,loaderContext?):Template
A synchronous version of load.
Parameters
• name: string
• environment: Environment
• context?: RenderContext
• globals?: ContextScope
• loaderContext?