smorken / string2blade
String to Blade compiler for Laravel
v10.2.0
2024-08-08 16:55 UTC
Requires
- php: ^8.1
- illuminate/mail: ^9.0|^10.0|^11.0
Requires (Dev)
- larastan/larastan: ^v2.9.8
- mockery/mockery: ^1.0
- orchestra/testbench: ^7.6|^8.0|^9.0
- phpunit/phpunit: ^11.0
- smorken/docker: *
- spatie/laravel-ignition: ^2.0
README
Provides the ability for Laravel to handle raw strings as blade templates.
Per the norm, you are responsible for what is in the template string! User provided input is probably a terrible idea.
The 'string' will be cached using a sha1 of the value so modifying the string value should result in laravel creating a new cached file.
License
This software is open-sourced software licensed under the MIT license
The Laravel framework is open-sourced software licensed under the MIT license
Installation
It should register itself automatically. If not, add to your config/app.php
:
...
'providers' => [
Smorken\String2Blade\ServiceProvider::class,
Smorken\String2Blade\MailerServiceProvider::class,
...
String2Blade Use
- Contract
// create view factory from DI
$view = App::make(\Smorken\String2Blade\Contracts\View\Factory::class);
$view->make('hello {{ $world }}!', ['world' => 'Earth']);
- Facade
use Smorken\String2Blade\Facades\String2Blade;
String2Blade::make('hello {{ $world }}')->with('world', 'Earth');
Mailable Use
- Blade template string
use Smorken\String2Blade\Mail\Mailable;
class TestMailable extends Mailable
{
public function build(): void
{
$this->to('fiz@example.com')
->from('buz@example.com')
->subject('Test Subject')
->view('hello {{ $world }}')
->with(
[
'world' => 'earth',
]
);
}
}
- Markdown template string
use Smorken\String2Blade\Mail\Mailable;
class TestMarkdownMailable extends Mailable
{
public function build(): void
{
$this->to('fiz@example.com')
->from('buz@example.com')
->subject('Test Subject')
->markdown($this->getMarkdown())
->with(
[
'world' => 'earth',
]
);
}
protected function getMarkdown(): string
{
return <<<STR
@component('mail::message')
# Hello
Your world is {{ \$world }}
@endcomponent
STR;
}
}