“@if"之前的 Laravel Blade 评论 [英] Laravel Blade comment before "@if"

查看:28
本文介绍了“@if"之前的 Laravel Blade 评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,在 HTML 中,我需要避免添加额外的空格,但我也需要添加@if()"块.为了实现这一点,我采用了这种方法:

Sometimes, in HTML, I need to avoid adding extra white space, but I also need to add "@if()" blocks. In order to accomplish this, I've taken this approach:

some text{--

--}@if($someCondition){--

--}more text with no space between

@endif

这种方法效果很好.但是,将我的开发和实时环境升级到 Laravel 5.5(从 Laravel 5.2)后,开发环境运行良好,但实时环境将上述刀片呈现为以下 HTML:

And this approach has been working great. However, after upgrading my development and live environments to Laravel 5.5 (from Laravel 5.2) the Development environment works fine, but the live environment renders the above blade into the following HTML:

some text@if($someCondition)more text with no space between

<?php endif; ?>

... 所以在刀片注释之后的if"语句被保留为纯文本.

... So the "if" statement immediately after the blade comment is left as plain text.

我知道这是可能的,因为我的两个开发环境都能正确呈现页面.我查看了 PHP 版本并复制了整个代码目录,但我根本找不到它们之间的任何区别,更不用说会导致处理方式不同的区别了.

I know that it's possible, because both my development environments render the page correctly. I've looked at PHP versions and copied over the entire code directory, but I cannot find any difference between them at all, let alone a difference that would cause this to be processed differently.

为什么 Laravel 的刀片引擎不允许在刀片评论后使用@"?

Is there any reason why Laravel's blade engine wouldn't allow a "@" right after blade comment?

使用 PHP 7.029、Laravel 5.5、CentOS.

Using PHP 7.029, Laravel 5.5, CentOS.

推荐答案

我发现了这个问题.该视图缓存在开发环境中,这就是它工作的原因.

I've discovered the issue. The view was cached on the development environments, which is why it was working.

Laravel 中似乎在 5.3 和 5.5 之间引入了一个新错误.在分析刀片的其余部分之前,刀片注释被删除,这可能会导致问题,正如我在此处的问题中所示.这以前在 Laravel 5.2 中有效.

It looks like there was a new bug introduced in Laravel somewhere between 5.3 and 5.5. The blade comments are being removed before the rest of the blade is analysed, which can cause issues as I showed in the question here. This was working previously in Laravel 5.2.

我确实找到了解决方法:

I did find a work around:

some text{{null

}}@if($someCondition){--

--}more text with no space between

@endif

产生有效的东西:

some text<?php echo e(null); ?><?php if($someCondition): ?>more text with no space between

<?php endif; ?>

这篇关于“@if"之前的 Laravel Blade 评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆