Expand description
Templates for emails, documents and notifications that your team edits, stored in the database, for Laravel Rust.
The code declares a template type, its variables and an example; everything else (the text, the subject, the sender, who gets the email, the language) lives in the database and is changed by people without a deploy:
use laravel_template_engine::{Recipient, TemplateData};
use serde::Serialize;
#[derive(Serialize, TemplateData)]
#[template(key = "order.placed", description = "An order was placed", example = OrderPlaced::example)]
pub struct OrderPlaced {
#[template(description = "The customer")]
pub customer: Recipient,
#[template(description = "The order")]
pub order: Order,
}
#[derive(Serialize, TemplateData)]
pub struct Order {
#[template(description = "Order number")]
pub number: String,
#[template(description = "Total")]
pub total: f64,
}
impl OrderPlaced {
fn example() -> Self {
Self {
customer: Recipient::new("olena@example.com").name("Olena").locale("uk"),
order: Order { number: "1042".into(), total: 1250.0 },
}
}
}
laravel_template_engine::send(order).await?;Register TemplateEngineServiceProvider and run laravel migrate. See the README for a
walkthrough.
Modules§
- editor
- What an editor UI reads: the template types, the filters and the syntax cheat sheet.
- events
- What the template engine dispatches. There’s no send log in the package: a listener of these events writes one if the application needs it.
- templates
- What an editor needs: checking, saving, previewing and test sends.
- transfer
- Moving templates between environments, such as from staging to production.
Structs§
- Arg
- A filter argument.
- Channel
- A channel notification templates can write for, such as
sms,slackortelegram. - Content
- A template’s text in one language.
- Default
Template - A template a type comes with.
laravel template-engine:install-defaultscreates it when the type has no template of that name, so the changes people make later are never overwritten. - Document
- A rendered document.
- Document
Settings - How a document is made.
- Field
- A named field of an object.
- Filter
- A filter an application adds for its templates, on top of the built-in ones.
- Filter
Spec - What templates may use a filter for, and how.
- Font
- A font PDF documents can use with
font-family: name. - Image
- A picture templates can show with
<img src="name">. - Issue
- One mistake in a template, for an editor to show next to the field.
- Layout
- A layout: shared HTML, such as a header, a footer and styles, that a template’s text goes
into at
{{ content }}. - Mail
Attachment - A file to attach to every email of a send, on top of the documents the templates attach. It travels through the queue, so it names a file or holds its bytes.
- Mail
Settings - Who an email goes to and what comes with it.
- Margins
- The space around a PDF page’s text, in millimeters.
- Notification
Settings - Which channel a notification template writes for.
- Notification
Texts - The active notification templates of one type with its data, ready to render a text per channel and language. Load it before sending a Laravel notification, keep it in the notification, and render in its channel methods, which can’t wait for the database:
- Pending
Document - A document from
document, to adjust before it’s rendered. - Pending
Template Mail - An email send from
mail. - Recipient
- Someone a message can go to. A template type’s fields of this type (or
Option<Recipient>, orVec<Recipient>) are its recipient variables: a template lists them into,ccorbccto send to them. Templates reademail,nameandlocalelike any other fields. - Rendered
Mail - An email’s parts, rendered.
- Rendered
Text - A notification’s text for one channel, rendered.
- Send
Template Mail - The queued job that renders one email and sends it. Rendering happens in the worker, so the email uses the template as it is when it goes out.
- Template
- A stored template: an ordinary Laravel Rust model, so creating, updating and deleting one
dispatches
Created<Template>,Updated<Template>andDeleted<Template>for audit packages. - Template
Engine Config - The package’s settings, read from the environment. Every one has a default, so nothing needs
to be set. An application changes them in
with_config: - Template
Engine Service Provider - Adds the package’s settings, its migration, its command and the application’s filters.
- Template
Input - A template to save, check or preview.
- Type
Info - A template type as the engine sees it at run time.
- Value
- Re-export for convenience. Represents a dynamically typed value in the template engine.
Enums§
- ArgKind
- How a filter argument is checked when the template gives it as a constant.
- Document
Format - The file format of a document.
- Input
Kind - What a filter’s input should be, for the checks.
- Kind
- What a template makes.
- Node
- The shape of a value a template can read.
- Orientation
- The paper’s orientation.
- Settings
- The settings of a template, by its kind.
- Template
Error - Something the template engine can’t do.
Traits§
- Describe
- A type that can describe its shape to the template engine. Derive it with
TemplateDatafor your own structs. - Template
Type - A template type: what one kind of event, such as
order.placed, gives its templates. Derive it withTemplateDataand#[template(key = "...", example = ...)]; the engine finds derived types on its own.
Functions§
- document
- Makes a document from
datawith its type’s active document template. - find_
type - The template type with
key. - An email send to adjust before it goes, for example with attachments.
- notification
- Loads the active notification templates of
data’s type. - send
- Sends the emails of every active email template of
data’s type, through the queue. Each address in a template’stogets its own email in its own language. Returns how many emails were queued. - type_of
- The template type
T. - types
- Every template type in the application, sorted by key.
Derive Macros§
- Template
Data - Describes a struct’s fields to the template engine. With
key, the struct is also a template type that the engine finds on its own. See thelaravel-template-enginecrate.