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
Functions
Create a ZSchemas.Documents.EmailTemplate
in the database
Retrieve a single ZSchemas.Documents.EmailTemplate
by one or more matching fields.
Update a ZSchemas.Documents.EmailTemplate
if it exists, add it to the DB otherwise
List ZSchemas.Documents.EmailTemplate
s from the database
Render an ZSchemas.Documents.EmailTemplate
to an ExploComm.Email
struct.
Link to this section Functions
create_email_template(attrs \\ %{})
Create a ZSchemas.Documents.EmailTemplate
in the database
delete_email_template(template)
Delete a ZSchemas.Documents.EmailTemplate
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
insert_or_update_email_template(template, attrs \\ %{})
Update a ZSchemas.Documents.EmailTemplate
if it exists, add it to the DB otherwise
list_email_templates(opts \\ [])
List ZSchemas.Documents.EmailTemplate
s from the database
Options
You can pass any of the following opts
for the list function:
query
- anEcto.Query
to start with. Defaults to showing all templates, and sorting byidentifier
.
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.