刀片-将变量打印到变量中
我正在尝试将一个变量打印到刀片模板中的另一个变量中.我有一个数据库变量,其中包含另一个变量的动态"数据.
I am trying to print a variable into another variable in a blade template. I have a variable from database that contains "dynamic" data from another variable.
示例:
$foo = 'user';
$bar = 'Hello {{$foo}}, how are you?';
在刀片服务器中,我正在这样做:
In blade I am doing this:
{!! $bar !!}
但是结果是:
Hello {{$foo}}, how are you?
我尝试过{{}},但结果是相同的.
I tried with {{}} but the result is the same.
我不能同时连接两个变量.例如:
I can't concatenate both variables. For example:
$foo = 'user';
$bar = 'Hello ' . $foo . ', how are you?';
这是不可能的,因为我没有变量的控制权,它们是从数据库动态填充的.
It isn't possible because I don't have the control of the variables, they are filled dynamically from database.
有什么想法/建议吗?
谢谢
如果输入不是来自用户的,请使用 eval
函数,并删除 {{...}} 代码>双花括号.您可以在
.blade.php
文件
Use eval
function if the input is not direct from user,and remove {{...}}
double curly bracket. you can used below code in .blade.php
file
@php
$foo = 'user';
$bar = eval('return "Hello $foo, how are you?";');
echo $bar;
@endphp
您将获得
Hello user, how are you?