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
Functions
Create a ZSchemas.Documents.HtmlTemplate
in the database
Retrieve a single ZSchemas.Documents.HtmlTemplate
by one or more matching fields.
Update a ZSchemas.Documents.HtmlTemplate
if it exists, add it to the DB otherwise
List ZSchemas.Documents.HtmlTemplate
s from the database
Render a ZSchemas.Documents.HtmlTemplate
as an HTML string
Link to this section Functions
create_html_template(attrs \\ %{})
Create a ZSchemas.Documents.HtmlTemplate
in the database
delete_html_template(template)
Delete a ZSchemas.Documents.HtmlTemplate
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
insert_or_update_html_template(template, attrs \\ %{})
Update a ZSchemas.Documents.HtmlTemplate
if it exists, add it to the DB otherwise
list_html_templates(opts \\ [])
List ZSchemas.Documents.HtmlTemplate
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.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.