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

时间:2015-06-04 23:44:12

标签: laravel-4 blade

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

这是image

检查我看到的HTML “ {{HTML :: ul(array('a','b','c'))}} “ 如果我可以删除引号,将显示刀片内容

1 个答案:

答案 0 :(得分:0)

您可以通过扩展Blade Compiler来编译存储在数据库行或变量中的刀片语法字符串。 解决方案代码取自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;
    }

}