简体   繁体   English

在Laravel刀片错误中评论“出了点问题”

[英]Commenting in Laravel blade error “Something went wrong”

I am trying to wrap my head around Laravel. 我想把头围在Laravel上。

I am commenting code out for later use. 我正在注释掉代码以备后用。 My problem occurs, when I have a snippet of code commented out, but the code is not "true". 当我有一段代码被注释掉,但是代码不是“ true”时,就会发生我的问题。

Example for what works for me: 适用于我的示例:

<head>
    <!-- {{ HTML::script('js/scrollTo.js'); }} -->
    {{ HTML::style('css/style.css'); }}
</head>

<head>
    <!-- Foo {{ HTML::script('js/scrollTo.js'); }} Bar -->
    {{ HTML::style('css/style.css'); }}
</head>

What doesn't work for me: 什么对我不起作用:

<head>
    <!-- {{ } HTML::script('js/scrollTo.js'); }} -->
    {{ HTML::style('css/style.css'); }}
</head>

Whenever I put something within the blade tags, the system makes an error. 每当我将某些内容放入刀片标签中时,系统都会出错。 Why I would even do this, i am not sure. 我不确定为什么还要这么做。 But what I don't understand is why the system makes an error when the tag is commentet out. 但是我不明白的是为什么当注释被注释掉时,系统会出错。

Use Blade Comments: 使用刀片评论:

<head>
    {{-- {{ } HTML::script('js/scrollTo.js'); }} --}}
    {{ HTML::style('css/style.css'); }}
</head>

The Blade tags still get rendered, even within an HTML comment (Blade is not a HTML parser, so it has no clue what <!-- means). 即使在HTML注释内,Blade标签仍会呈现(Blade不是HTML解析器,因此不知道<!--是什么意思)。 Your resulting view code is going to be: 您得到的视图代码将是:

<!-- <?php } HTML::script('js/scrollTo.js'); ?> -->

which is a parse error. 这是一个解析错误。 You can use Blade comments: 您可以使用Blade注释:

{{-- {{ } HTML::script('js/scrollTo.js'); }} --}}

but the real question is why not fix the slightly invalid code in the first place? 但真正的问题是,为什么不首先修复稍微无效的代码?

I don't know why, but it doesn't work because it is php. 我不知道为什么,但是它不起作用,因为它是php。 So whenever you "comment it out" it is still ran and will still return an error when the php is 'bad'. 因此,每当您“注释掉它”时,它仍然会运行,并且在php“损坏”时仍会返回错误。 If you do want to comment them out then you can do it this way: 如果您确实要注释掉它们,则可以通过以下方式进行操作:

{{ dd($non_existent_value) }} <- causes error {{ dd($non_existent_value) }} <-导致错误

<!-- {{ dd($non_existent_value) }} --> <- also causes error <!-- {{ dd($non_existent_value) }} --> <-也会导致错误

{{ ''# dd($non_existent_value) }} <- echo's '', aka nothing {{ ''# dd($non_existent_value) }} < {{ ''# dd($non_existent_value) }}的,也就是什么

<!-- {{ ''# dd($non_existent_value) }} --> <- also echo's '', aka nothing <!-- {{ ''# dd($non_existent_value) }} --> <-也回显'',也就是

If you take a look at the code after you get errors on this you will see that with the first examples it tries to do <?php echo $non_existent_value ?> , with the latter it will do <?php echo '' # $non_existent_value ?> and thus echo '', or nothing. 如果在出现错误后查看代码,您会发现在第一个示例中它尝试执行<?php echo $non_existent_value ?> ,而在后一个示例中它将执行<?php echo '' # $non_existent_value ?>并因此回显''或什么也没有。

Blade also provides a way to comment out the entire thing, just append '--' after the opening '{{' and before the closing '}}'. Blade还提供了一种注释掉整个内容的方法,只需在开头“ {{”之后和结尾“}}”之前附加“-”。 Like so: 像这样:

{{-- dd($someVar) --}}

Both methods above are correct, although the first does not comment out the <?php echo ?> part but only what comes after 'echo'. 上面的两种方法都是正确的,尽管第一种方法没有注释掉<?php echo ?>部分,而是仅注释了'echo'之后的内容。

暂无
暂无

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

相关问题 哎呀,看起来像出事了。 LARAVEL错误 - Whoops, looks like something went wrong. LARAVEL ERROR 哎呀,看起来出事了。 尝试在内置服务器上运行时 Laravel 5 中的错误 - Whoops, looks like something went wrong. error in Laravel 5 when trying to run on built in server Laravel v5.2.38的错误报告比“糟糕,好像出了点问题”更好。 - Laravel v5.2.38 better error reporting than “Whoops, looks like something went wrong.” 从 xlxs 文件插入 10000 行时,浏览器抛出错误“糟糕,出了点问题” - laravel - Browser throws error “Whoops, something went wrong” when insertin 10000 rows from xlxs file - laravel 使用laravel 5.4项目在浏览器上进行多次刷新时会出现错误“糟糕,好像出了点问题。” - multiple refresh on browser with laravel 5.4 project get error “Whoops, looks like something went wrong.” 哎呀,看起来出事了。 Laravel 5.0 - Whoops, looks like something went wrong. Laravel 5.0 Laravel Form:哎呀,好像出了点问题 - Laravel Form: Whoops, looks like something went wrong Laravel 社交名媛通过 facebook 登录结果 抱歉,出了点问题 - Laravel socialite login through facebook results in Sorry, something went wrong “哇,看起来好像出了点问题。” Laravel 4.1 - “Whoops, looks like something went wrong.” Laravel 4.1 哎呀,看起来出事了。 共享主机错误 - Whoops, looks like something went wrong. error on shared hosting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM