刀片-将变量打印到变量中 [英] Blade - Print variable into variable

查看:62
本文介绍了刀片-将变量打印到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个变量打印到刀片模板中的另一个变量中.我有一个数据库变量,其中包含另一个变量的动态"数据.

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?

这篇关于刀片-将变量打印到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆