【问题标题】:How to process string like blade template in laravel?如何在laravel中处理类似刀片模板的字符串?
【发布时间】:2017-08-20 09:38:22
【问题描述】:

我有代码:

$a = test
$string = 'test {{ $a }}';

我想将 $string 变量中的字符串作为刀片模板处理。我知道我可以将其保存到临时视图中,如下所示:

$a = test
$string = 'test {{ $a }}';
file_put_contents('temp.blade.php', $string);
$processedString = View::make('temp', compact($a));

但我不想保存临时文件,我想要类似的东西:

$a = test
$string = 'test {{ $a }}';
$processedString = View::makeFromString($string, compact($a));

有什么想法吗?

【问题讨论】:

标签: php laravel laravel-5.2


【解决方案1】:

不,默认情况下laravel不支持这个,但是这个包

https://github.com/TerrePorter/StringBladeCompiler

对我来说就像魅力一样工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 2021-03-14
    • 2016-12-18
    • 2014-01-03
    • 2013-04-29
    相关资源
    最近更新 更多