如何显示存储在 Db 行中的 Blade 内容

How to Display Blade Content stored in a Db row

如何有效地显示存储在数据库中的 Blade 代码,而不是显示为一行代码?

这里是image

检查 html 我明白了 “ {{HTML::ul(数组('a', 'b', 'c'))}} “ 如果我可以去掉引号,将显示 blade 内容

您可以通过扩展 Blade Compiler 编译 blade 语法字符串,存储在 DB 行或变量中。 解决方案代码取自here,我自己没有测试代码。

<?php namespace Laravel\Enhanced;

use Illuminate\View\Compilers\BladeCompiler as LaraveBladeCompiler;

class BladeCompiler extends LaraveBladeCompiler {

    /**
     * Compile blade template with passing arguments.
     *
     * @param  [type] $value [description]
     * @param  array  $args  [description]
     * @return [type]        [description]
     */
    public function compileWiths($value, array $args = array())
    {
        $generated = parent::compileString($value);

        ob_start() and extract($args, EXTR_SKIP);

        // We'll include the view contents for parsing within a catcher
        // so we can avoid any WSOD errors. If an exception occurs we
        // will throw it out to the exception handler.
        try
        {
            eval('?>'.$generated);
        }

        // If we caught an exception, we'll silently flush the output
        // buffer so that no partially rendered views get thrown out
        // to the client and confuse the user with junk.
        catch (\Exception $e)
        {
            ob_get_clean(); throw $e;
        }

        $content = ob_get_clean();

        return $content;
    }

}