Write data reports in Twig and deliver them via email, CSV export, or queue jobs.
- Craft CMS 5.5+
- PHP 8.2+
composer require superbig/craft-reportsThen install the plugin from the Craft Control Panel or run:
./craft plugin/install reports- Go to Reports in the CP sidebar
- Click New and give your report a name and handle
- Write your report in Twig using the
resultvariable:
{% set users = craft.users.lastLoginDate('> ' ~ now|date_modify('-30 days')|atom).all() %}
{% do result.setHeader(['Username', 'Name', 'Email']) %}
{% for user in users %}
{% do result.append([user.username, user.getName(), user.email]) %}
{% endfor %}- Click Run to see the output, or Export to download as CSV
Create a config/reports.php file to override defaults:
| Option | Type | Default | Description |
|---|---|---|---|
enableScheduler |
bool |
true |
Enable the report scheduler |
helpers |
array |
[] |
Custom helper functions available in report templates |
pluginName |
string |
'Reports' |
Override the plugin name in the CP |
<?php
return [
'enableScheduler' => true,
'pluginName' => 'Reports',
'helpers' => [],
];Report templates receive two variables:
result— aReportResultmodel for building tabular outputreport— theReportmodel for the current report
| Method | Description |
|---|---|
result.setHeader(array) |
Set column headers |
result.append(array) |
Add a row (or array of rows) |
result.setFilename(string) |
Set the CSV export filename |
result.setContent(array) |
Replace all rows |
result.getHeader() |
Get current headers |
result.getContent() |
Get all rows |
{% set orders = craft.orders.dateOrdered('> ' ~ now|date_modify('-7 days')|atom).all() %}
{% do result.setHeader(['Order #', 'Email', 'Total', 'Date']) %}
{% do result.setFilename('weekly-orders') %}
{% for order in orders %}
{% do result.append([order.number, order.email, order.totalPrice|currency, order.dateOrdered|date]) %}
{% endfor %}Report targets deliver report results to external channels. Currently supported:
- Email — Send report results as CSV attachments
- Go to Reports → Report Targets
- Click New, select Email as the target type
- Configure recipients and email body template
- Connect one or more reports to the target
The email body template has access to reports (connected reports) and target (the target model):
Report generated for {{ target.name }}
{% for report in reports %}
- {{ report.name }}
{% endfor %}Run report targets from the CLI — useful for cron jobs or long-running reports:
# Run by handle
./craft reports/default/run-target weekly-summary
# Run by ID
./craft reports/default/run-target 5
# List all targets
./craft reports/default/list-targets| Permission | Description |
|---|---|
| Run Reports | View and run reports |
| Manage Reports | Create, edit, and delete reports |
| Manage Export Targets | Create, edit, and manage report targets |
- Requires Craft 5.5+ and PHP 8.2+
mobileGrademethod removed (if referenced in custom code)FILTER_SANITIZE_STRINGreplaced (PHP 8.2 removal)- Widget
iconPath()removed (Craft 5 change)
Brought to you by Superbig