简体   繁体   English

laravel刀片使用substr方法禁用转义

[英]laravel blade disable escape with substr method

in Laravel 5 I'm trying to disable escaping in a Blade template which currently has the following: 在Laravel 5中,我试图禁用当前具有以下功能的Blade模板中的转义:

{{ substr($v["CONTENT"],0,140)}}

I tried with 我尝试过

{{ !! substr($v["CONTENT"],0,140)}}

but it returns a 1 instead of a substring of text of 140 characters. 但它返回1而不是140个字符的文本子字符串。 I cannot move the substr functions inside a controller because I'm inside of a loop: 我无法在控制器内移动substr函数,因为我在循环内:

@foreach($articleList as $k => $v)

any idea? 任何想法?

You need to use {!! 您需要使用{!! and !!} to display unescaped data. !!}以显示未转义的数据。 There must not be any space between the curly brace and the exclamation points. 大括号和感叹号之间不能有任何空格。

You're getting a 1 because your blade tags are wrong, and your !! 您得到1原因是刀片标记错误,而您的!! is being treated as two not operators, which is equating to {{ true }} . 被视为两个not运算符,相当于{{ true }}

You want: 你要:

{!! substr($v["CONTENT"], 0, 140) !!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM