Monday, March 13, 2017

Process blade templates inside strings

I have a scenario, where the user can set a text template and use placeholders in braces, that should be replaced dynamicly.

For example the user input could be strings like:

$userinput = '<p> Hello  <\p>';
$userinput = '<p> Hi  <\p>';

I want to display this input with the expanded placeholders in a view message.blade.php

@section('content')
    {!! $userinput !!}
@stop

The HTML gets rendered correctly, but but of course isnt substituted with 'Alice'.

view('message')->with([
            'userinput' => $userinput,
            'name' => 'Alice',]);

Is there a simple way to process the inner placeholder as well? Can i interpret the blade file a second time?

PS: I am aware, that unescaped userinputs are evil.



via Streamfighter

Advertisement