Reputation: 7138
I have unusual situation which I have to print dynamic variables inside another variable in blade but not sure if it's possible or how to?
// this returns content of my template which has dynamic data in it
{!! $data['template']->content !!}
// inside that template content I have to get user name like
{{$data['customer']->name}}
the problem is printing customer name
here is sample result
Note:
$data['customer']
is provided in view page but the problem is how to get it inside my template data.
My code is basically is just sample code i shared above (it's all happening in blade)
{!! $data['template']->content!!}
// inside `content` there is like:
<h4>{{$data['customer']->customer_lastname}}</h4>
How can I get {{$data['customer']}}
printed inside {!! $data['template']->content!!}
?
Upvotes: 0
Views: 3462
Reputation: 2271
Per my comments, you could treat and compile the template string with pre-defined patterns. For example, for customer names you could do this when constructing content text:
<h4>:customer_name</h4>
And then before sending the data to blade:
$templateContent = $data['template']->content;
$templateContent = preg_replace("/:customer_name/i", $data['customer']->name, $templateContent);
return view('yourview', compact('templateContent'));
And, in blade:
{!! $templateContent !!}
Upvotes: 1