Skip to content

[Feature] Implement a notification template engine #2105

Open
@alexjustesen

Description

@alexjustesen

📃 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

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}

Image

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions