Runbox.Notifications.TemplateHelper (runbox v7.0.1)

Set of utility functions for use in notification templates.

Link to this section Summary

Functions

Returns a URL to the asset detail.

Formats a number by separating thousands with a separator.

Formats timestamp into the given format in the given timezone.

Wraps the given EEx content with a EEx template.

Returns the UI url.

Link to this section Functions

Link to this function

asset_link(asset_id, ui_type \\ :new)

@spec asset_link(String.t(), :new | :old) :: String.t()

Returns a URL to the asset detail.

The type of UI can be specified, and the link is generated to work with that UI. Can be :new or :old.

Link to this function

format_number(number, separator \\ " ")

Formats a number by separating thousands with a separator.

Link to this function

format_ts(ts, format_str, target_tz \\ "Etc/UTC")

Formats timestamp into the given format in the given timezone.

Link to this macro

include_template(source, template_name, context \\ [], macro_params)

(macro)

Wraps the given EEx content with a EEx template.

Templates can be bundled with a scenario or be a part of the system, source should be set to scenario_name for scenario-based templates and :system for templates bundled with the system.

The templates that can be included, so called shared templates, are stored in shared folder (scenarios/priv/notifications/{scenario_name}/shared). Each shared template consists of two files - header and footer - which are wrapped around the given content. The filenames have _header and _footer appended, for template_name = "email" the two filenames are email_header.eex and email_footer.eex. System templates are stored in apps/asset_map/templates/shared.

Via context you can pass additional parameters to the shared template (passed as assigns). The expected context depends on the template.

example-usage

Example usage

<% alias Runbox.Notifications.TemplateHelper %>
<% require TemplateHelper %>
<%= TemplateHelper.include_template({"test", 1}, "email_rich", title: "Test email") do %>
  <h1>Test Email</h1>
  <p>This text is surrounded by the template...</p>
<% end %>

Returns the UI url.