我遇到异常情况,必须在刀片中的另一个变量内打印动态变量,但不确定是否可行或如何做?
// 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}}
问题出在打印customer name
这是示例结果
注意::视图页面中提供了
$data['customer']
,但问题是如何将其放入我的模板数据中。
我的代码基本上只是我上面共享的示例代码(全部发生在刀片中)
{!! $data['template']->content!!}
// inside `content` there is like:
<h4>{{$data['customer']->customer_lastname}}</h4>
如何在{{$data['customer']}}
内打印{!! $data['template']->content!!}
?
答案 0 :(得分:1)
根据我的评论,您可以使用预定义的模式来处理和编译模板字符串。例如,对于客户名称,您可以在构造内容文本时执行以下操作:
<h4>:customer_name</h4>
然后将数据发送到刀片之前:
$templateContent = $data['template']->content;
$templateContent = preg_replace("/:customer_name/i", $data['customer']->name, $templateContent);
return view('yourview', compact('templateContent'));
而且,在刀片服务器中:
{!! $templateContent !!}