繁体   English   中英

如何在 laravel 刀片中打印变量内部变量

[英]How to print variable inside variable in laravel blade

我有不寻常的情况,我必须在刀片的另一个变量中打印动态变量,但不确定它是否可能或如何?

例子

// 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']-&gt;customer_lastname}}</h4>

问题

我怎样才能让{{$data['customer']}}{!! $data['template']->content!!} {!! $data['template']->content!!} ?

根据我的评论,您可以使用预定义的模式处理和编译模板字符串。 例如,对于客户名称,您可以在构建内容文本时执行此操作:

<h4>:customer_name</h4>

然后在将数据发送到刀片之前:

$templateContent = $data['template']->content;
$templateContent = preg_replace("/:customer_name/i", $data['customer']->name, $templateContent);
return view('yourview', compact('templateContent'));

并且,在刀片中:

{!! $templateContent !!} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM