Open
Description
📃 Description
Starting to think about a templating engine so that the body and/or subject of a notification can be customized from within the UI.
Important
This is just a brain dump of thoughts there is no ETA on this feature and it could be killed off if I think the juice isn't worth the squeeze.
👀 Resources
- https://github.com/spatie/laravel-database-mail-templates
- https://stackoverflow.com/questions/15065387/how-can-i-replace-a-variable-in-a-string-with-the-value-in-php
Practical options
Parse markdown content
This method translates the string to the given values and then parses the markdown to HTML.
use App\Models\Result;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
public function parseBody(Result $result)
{
// Get the sample markdown to simulate user-driven content
$contents = Storage::get('sample_body.md');
// Translate the file contents
$output = strtr($contents, [
'{$id}' => $result->id,
'{$download}' => $result->download,
'{$upload}' => $result->upload,
'{$ping}' => $result->ping,
]);
echo Str::markdown($output, [
'allow_unsafe_links' => false,
'html_input' => 'strip',
'max_nesting_level' => 5,
]);
}
# Speedtest Tracker Result
- Result: {$id}
- Download: {$download}
- Upload: {$upload}
- Ping: {$ping}
- Invalid: {$invalid}