Skip to main content

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

FetchLoader

Overrides

Loader.constructor

Defined in

src/builtin/loaders/fetch_loader.ts:80

Properties

baseURL

readonly baseURL: 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

Loader.getSource

Defined in

src/builtin/loaders/fetch_loader.ts:92


getSourceSync()

getSourceSync(): TemplateSource

A synchronous version of getSource.

Returns

TemplateSource

See

getSource

Overrides

Loader.getSourceSync

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

Loader.load

Defined in

src/loader.ts:76


loadSync()

loadSync(name, environment, context?, globals?, loaderContext?): Template

A synchronous version of load.

Parameters

name: string

environment: Environment

context?: RenderContext

globals?: ContextScope

loaderContext?

Returns

Template

See

load

Inherited from

Loader.loadSync

Defined in

src/loader.ts:97