Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions quickstart/laravel/templates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ php artisan lettr:pull
```

Options:
- `--template=slug` - Pull a specific template
- `--template=slug` - Pull a specific template. Exits with a failure code if it doesn't exist
- `--as-html` - Save as HTML instead of Blade
- `--with-mailables` - Also generate Mailable classes
- `--with-mailables` - Also generate Mailable and DTO classes
- `--skip-templates` - With `--with-mailables`, generate only DTOs and Mailables, without downloading templates
- `--dry-run` - Preview what would be downloaded without writing files

By default, templates are saved as Blade files to `resources/views/emails/lettr/`. HTML files go to `resources/templates/lettr/`. Both paths are configurable in `config/lettr.php`.

When converting to Blade, merge tags become variables (`{{first_name}}` → `{{ $first_name }}`) and loops become null-safe `@foreach` blocks whose items are read as arrays (`{{#each items}}{{this.name}}` → `@foreach($items ?? [] as $item){{ $item['name'] }}`), which is the shape generated DTOs pass to the view.

<Tip>
Use `--with-mailables` to generate ready-to-use Mailable classes alongside the templates. This is the fastest way to scaffold email classes from your existing Lettr templates.
Use `--with-mailables` to generate ready-to-use Mailable classes alongside the templates. This is the fastest way to scaffold email classes from your existing Lettr templates. See [Mailable Classes](/quickstart/laravel/type-safety#mailable-classes) for the two kinds of Mailable it can generate.
</Tip>

## Push Templates to Lettr
Expand All @@ -91,8 +95,10 @@ Upload local Blade templates to Lettr, creating them if they do not exist:
php artisan lettr:push
```

Without `--path`, the command looks for templates in `blade_path` from `config/lettr.php` (where `lettr:pull` saves them), then in `resources/views/emails`, `mails`, `email` and `mail`, and asks before using a folder.

Options:
- `--path=` - Custom path to the templates directory
- `--path=` - Custom path to the templates directory, absolute or relative to your project root
- `--template=filename` - Push only one template
- `--purpose=` - Module to create the templates in: `transactional` (default) or `campaign`
- `--dry-run` - Preview what would be created without pushing
Expand Down Expand Up @@ -121,17 +127,22 @@ foreach ($response->templates as $template) {
}
```

Get a specific template:
Get a specific template and its merge tags:

```php
$template = Lettr::templates()->get('welcome-email');

echo $template->name;
echo $template->activeVersion;
print_r($template->mergeTags);

$response = Lettr::templates()->getMergeTags('welcome-email', version: $template->activeVersion);

foreach ($response->mergeTags as $mergeTag) {
echo $mergeTag->key . ($mergeTag->required ? ' (required)' : '');
}
```

The `mergeTags` property returns an array of merge tag names defined in the template, which is useful for validating your substitution data before sending.
Each merge tag has a `key`, a `required` flag, a `type`, and `children` for loop blocks, which is useful for validating your substitution data before sending.

## What's Next

Expand Down
Loading