【问题标题】:Possible for Blade not to escape certain html tags?Blade 可能不会转义某些 html 标签?
【发布时间】:2016-05-30 06:55:50
【问题描述】:

在 Laravel Blade 中,{{...}} 将转义所有 HTML 标签。

是否可以排除某些标签被转义,例如<p><br/>?虽然我只能{!!...!!}},但它允许显示任何标签。

【问题讨论】:

    标签: laravel-5.1 blade


    【解决方案1】:

    你应该去
    vendor\laravel\framework\src\Illuminate\View\Compilers\BladeCompiler.php
    并更改此功能

        protected function compileRawEchos($value)
    {
        $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->rawTags[0], $this->rawTags[1]);
    
        $callback = function ($matches) {
            $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
    
            return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$this->compileEchoDefaults($matches[2]).'; ?>'.$whitespace;
        };
    
        return preg_replace_callback($pattern, $callback, $value);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-24
      • 1970-01-01
      • 2023-03-14
      • 2014-05-30
      • 2011-08-22
      • 2019-08-03
      • 1970-01-01
      • 2012-04-21
      相关资源
      最近更新 更多