template-loader.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Injector, RequestContext } from '@vendure/core';
  2. import { LoadTemplateInput, Partial } from '../types';
  3. /**
  4. * @description
  5. * Loads email templates based on the given request context, type and template name
  6. * and return the template as a string.
  7. *
  8. * @example
  9. * ```ts
  10. * import { EmailPlugin, TemplateLoader } from '\@vendure/email-plugin';
  11. *
  12. * class MyTemplateLoader implements TemplateLoader {
  13. * loadTemplate(injector, ctx, { type, templateName }){
  14. * return myCustomTemplateFunction(ctx);
  15. * }
  16. * }
  17. *
  18. * // In vendure-config.ts:
  19. * ...
  20. * EmailPlugin.init({
  21. * templateLoader: new MyTemplateLoader()
  22. * ...
  23. * })
  24. * ```
  25. *
  26. * @docsCategory core plugins/EmailPlugin
  27. * @docsPage TemplateLoader
  28. * @docsWeight 0
  29. */
  30. export interface TemplateLoader {
  31. /**
  32. * @description
  33. * Load template and return it's content as a string
  34. */
  35. loadTemplate(injector: Injector, ctx: RequestContext, input: LoadTemplateInput): Promise<string>;
  36. /**
  37. * @description
  38. * Load partials and return their contents.
  39. * This method is only called during initialization, i.e. during server startup.
  40. */
  41. loadPartials?(): Promise<Partial[]>;
  42. }