Z.Documents.EmailTemplates (Portico/Z v0.1.0)

Context module for ZSchemas.Documents.EmailTemplate data.

Handles template rendering, as well as CRUD actions for the template data.

Link to this section Summary

Link to this section Functions

Link to this function

create_email_template(attrs \\ %{})

Create a ZSchemas.Documents.EmailTemplate in the database

Link to this function

delete_email_template(template)

Delete a ZSchemas.Documents.EmailTemplate

Link to this function

get_email_template(id)

Retrieve a single ZSchemas.Documents.EmailTemplate by one or more matching fields.

Defaults to ID, but can be passed a Keyword list of field name/values to match.

Examples

iex> Z.Documents.EmailTemplates.get_email_template("abc-123-def-456")
%ZSchemas.Documents.EmailTemplate{}

iex> Z.Documents.EmailTemplates.get_email_template(identifier: "cool")
%ZSchemas.Documents.EmailTemplate{}

iex> Z.Documents.EmailTemplates.get_email_template(identifier: "empty", name: "doesn't exist")
nil
Link to this function

insert_or_update_email_template(template, attrs \\ %{})

Update a ZSchemas.Documents.EmailTemplate if it exists, add it to the DB otherwise

Link to this function

list_email_templates(opts \\ [])

List ZSchemas.Documents.EmailTemplates from the database

Options

You can pass any of the following opts for the list function:

  • query - an Ecto.Query to start with. Defaults to showing all templates, and sorting by identifier.
Link to this function

render(template)

Specs

render(%ZSchemas.Documents.EmailTemplate{
  __meta__: term(),
  bcc: term(),
  body_as_html: term(),
  body_as_typed: term(),
  cc: term(),
  from_email: term(),
  from_name: term(),
  headers: term(),
  id: term(),
  identifier: term(),
  inserted_at: term(),
  name: term(),
  subject: term(),
  tags: term(),
  to_email: term(),
  to_name: term(),
  updated_at: term(),
  variables: term()
}) :: String.t() | {:error, term()}

Render an ZSchemas.Documents.EmailTemplate to an ExploComm.Email struct.

Injects any default values from template.variables as EEx assigns, if any are set.

Passes to Utility.EExSafeEngine as the EEx rendering engine. Returns "SYNTAX ERROR" in the relevant field if there's a rendering error.

If merged_variables are sent, those will overwrite any template defaults. Returns {:error, missing_variables: [:list, :of, :names]} if merged_variables doesn't contain keys for all required variables from the template.

Link to this function

render(template, merged_variables)