fico7489
fico7489

Reputation: 8560

How to process string like blade template in laravel?

I have code :

$a = test
$string = 'test {{ $a }}';

I want to process string in $string variable as blade template. I know I can save this to temp view something like this:

$a = test
$string = 'test {{ $a }}';
file_put_contents('temp.blade.php', $string);
$processedString = View::make('temp', compact($a));

but I don't want to save temp file, I want something like :

$a = test
$string = 'test {{ $a }}';
$processedString = View::makeFromString($string, compact($a));

Any ideas ?

Upvotes: 1

Views: 1432

Answers (1)

fico7489
fico7489

Reputation: 8560

No, by default laravel does not support this, but this package

https://github.com/TerrePorter/StringBladeCompiler

work like charm for me.

Upvotes: 1

Related Questions