将html传递给@section的第二个参数

时间:2019-05-16 11:26:25

标签: laravel laravel-blade

我有一个master.blade.php,其中包含curl -L -s -w "%{stderr}%{size_download}:%{speed_download}\n" http://..someurl../1000mb 2>&1

我想像这样@yield('page_tagline')

使用它

如果翻译中不包含任何html,但是包含html,这将起作用。

那么我怎么能像这样使用它而不用刀片逃脱呢?

2 个答案:

答案 0 :(得分:1)

解决此问题的一种方法是使用HtmlString类:

@section('page_tagline', new \Illuminate\Support\HtmlString( __('pages.home.tagline')))

然后,您可以更进一步,为macro类或global helper function创建一个Str


宏示例

在您AppServiceProvider(或您想要的任何服务提供商)中,将以下内容添加到boot方法中:

Str::macro('html', function ($string) {
    return new HtmlString($string);
});

请不要忘记将以下use语句添加到该类中:

use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

然后您@section看起来像:

@section('content', Str::html( __('pages.home.tagline')))

答案 1 :(得分:0)

您应该使用

@section('page_tagline')
    {!! __('pages.home.tagline') !!}
@endsection

这样,您可以将HTML放在标语中