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

Context module for ZSchemas.Documents.HtmlTemplate data.

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

See the HTML Templates Guide for more detail about how we use the HTML template system + modules.

Link to this section Summary

Link to this section Functions

Link to this function

create_html_template(attrs \\ %{})

Create a ZSchemas.Documents.HtmlTemplate in the database

Link to this function

delete_html_template(template)

Delete a ZSchemas.Documents.HtmlTemplate

Link to this function

get_html_template(id)

Retrieve a single ZSchemas.Documents.HtmlTemplate 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.HtmlTemplates.get_html_template("abc-123-def-456")
%ZSchemas.Documents.HtmlTemplate{}

iex> Z.Documents.HtmlTemplates.get_html_template(identifier: "cool")
%ZSchemas.Documents.HtmlTemplate{}

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

insert_or_update_html_template(template, attrs \\ %{})

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

Link to this function

list_html_templates(opts \\ [])

List ZSchemas.Documents.HtmlTemplates 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.HtmlTemplate{
  __meta__: term(),
  css: term(),
  height_in: term(),
  html: term(),
  html_documents: term(),
  id: term(),
  identifier: term(),
  inserted_at: term(),
  name: term(),
  tags: term(),
  updated_at: term(),
  variables: term(),
  width_in: term()
}) :: String.t() | {:error, term()}

Render a ZSchemas.Documents.HtmlTemplate as an HTML string

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

Passes to Utility.EExSafeEngine as the EEx rendering engine. Returns {:error: :syntax if there's an EEx 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)