---
title: "TemplateLoader"
generated: true
---
<GenerationInfo sourceFile="packages/email-plugin/src/template-loader/template-loader.ts" sourceLine="32" packageName="@vendure/email-plugin" />

Loads email templates based on the given request context, type and template name
and return the template as a string.

*Example*

```ts
import { EmailPlugin, TemplateLoader } from '@vendure/email-plugin';

class MyTemplateLoader implements TemplateLoader {
     loadTemplate(injector, ctx, { type, templateName }){
         return myCustomTemplateFunction(ctx);
     }
}

// In vendure-config.ts:
...
EmailPlugin.init({
    templateLoader: new MyTemplateLoader()
    ...
})
```

```ts title="Signature"
interface TemplateLoader {
    loadTemplate(injector: Injector, ctx: RequestContext, input: LoadTemplateInput): Promise<string>;
    loadPartials?(): Promise<Partial[]>;
}
```

<div className="members-wrapper">

### loadTemplate

<MemberInfo kind="method" type={`(injector: <a href='/reference/typescript-api/common/injector#injector'>Injector</a>, ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, input: <a href='/reference/core-plugins/email-plugin/email-plugin-types#loadtemplateinput'>LoadTemplateInput</a>) => Promise<string>`}   />

Load template and return it's content as a string
### loadPartials

<MemberInfo kind="method" type={`() => Promise<Partial[]>`}   />

Load partials and return their contents.
This method is only called during initialization, i.e. during server startup.


</div>
<GenerationInfo sourceFile="packages/email-plugin/src/template-loader/file-based-template-loader.ts" sourceLine="17" packageName="@vendure/email-plugin" />

Loads email templates from the local file system. This is the default
loader used by the EmailPlugin.

```ts title="Signature"
class FileBasedTemplateLoader implements TemplateLoader {
    constructor(templatePath: string)
    loadTemplate(_injector: Injector, _ctx: RequestContext, { type, templateName }: LoadTemplateInput) => Promise<string>;
    loadPartials() => Promise<Partial[]>;
}
```
* Implements: <DocsLink href="/reference/core-plugins/email-plugin/template-loader#templateloader">`TemplateLoader`</DocsLink>



<div className="members-wrapper">

### constructor

<MemberInfo kind="method" type={`(templatePath: string) => FileBasedTemplateLoader`}   />


### loadTemplate

<MemberInfo kind="method" type={`(_injector: <a href='/reference/typescript-api/common/injector#injector'>Injector</a>, _ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, { type, templateName }: <a href='/reference/core-plugins/email-plugin/email-plugin-types#loadtemplateinput'>LoadTemplateInput</a>) => Promise<string>`}   />


### loadPartials

<MemberInfo kind="method" type={`() => Promise<Partial[]>`}   />




</div>
