如何在像laravel 4这样的刀片中注释代码?

时间:2022-10-18 17:19:11

I have migrated my app from laravel 4.2 to laravel 5

我已将我的应用程序从laravel 4.2迁移到laravel 5

I am currently having this problem, when even I have old comments like this:

我目前遇到这个问题,即使我有这样的旧评论:

{{--{{link_to_route('language.select', 'English', array('en'))}}--}}

Will result into error at laravel 5, I will have this error:

在laravel 5会导致错误,我会有这个错误:

FatalErrorException in 18b6386ebc018eb0c0e76f105eba4286 line 263:
syntax error, unexpected '{'

which is compiled into:

编译成:

 <?php echo --{{link_to_route('language.select', 'English', array('en')); ?>--}}

I already added laravel 4 backward comparability support at register@ServiceProvider as:

我已在register @ ServiceProvider中添加了laravel 4向后可比性支持:

\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');

but how can I add laravel 4 backward comparability for comments {{-- --}} ?

但是如何为评论{{ - - }}添加laravel 4向后可比性?

edit:

how to comment this in laravel 5:

如何在laravel 5中评论这个:

<li {{ (Request::is('/') ? ' class="active"' : '') }}><a href="{{{ URL::to('') }}}">{{trans('messages.Home')}}</a></li>

3 个解决方案

#1


Since you change your content tags from {{ to {{{ comment tags are now {{{-- not {{--

由于您将内容标记从{{更改为{{{评论标记现在是{{{ - not {{ -

#2


From lavarel 5 doc

来自lavarel 5 doc

Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.

注意:回显应用程序用户提供的内容时要非常小心。始终使用双花括号语法来转义内容中的任何HTML实体。

{{-- This comment will not be in the rendered HTML --}}

So I think this should works :

所以我认为这应该有效:

<li {{-- (Request::is('/') ? ' class="active"' : '') --}}>
     <a href="{{-- URL::to('') --}}">{{--trans('messages.Home')--}}</a>
</li>

And to comment the whole HTML add :

并评论整个HTML添加:

{{{-- HTML --}}}

#3


In general the comment syntax has not changed in Laravel 5, however...

一般来说,Laravel 5中的注释语法没有改变,但是......

The characters for comments are derived by the content tags. Since you set them to {{{ and }}} with Blade::setContentTags('{{{', '}}}'); you have to use them now for your comments as well:

注释的字符由内容标记派生。由于您使用Blade :: setContentTags('{{{','}}}')将它们设置为{{{和}}};你现在必须使用它们来征求你的意见:

{{{-- {{link_to_route('language.select', 'English', array('en'))}} --}}}

#1


Since you change your content tags from {{ to {{{ comment tags are now {{{-- not {{--

由于您将内容标记从{{更改为{{{评论标记现在是{{{ - not {{ -

#2


From lavarel 5 doc

来自lavarel 5 doc

Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.

注意:回显应用程序用户提供的内容时要非常小心。始终使用双花括号语法来转义内容中的任何HTML实体。

{{-- This comment will not be in the rendered HTML --}}

So I think this should works :

所以我认为这应该有效:

<li {{-- (Request::is('/') ? ' class="active"' : '') --}}>
     <a href="{{-- URL::to('') --}}">{{--trans('messages.Home')--}}</a>
</li>

And to comment the whole HTML add :

并评论整个HTML添加:

{{{-- HTML --}}}

#3


In general the comment syntax has not changed in Laravel 5, however...

一般来说,Laravel 5中的注释语法没有改变,但是......

The characters for comments are derived by the content tags. Since you set them to {{{ and }}} with Blade::setContentTags('{{{', '}}}'); you have to use them now for your comments as well:

注释的字符由内容标记派生。由于您使用Blade :: setContentTags('{{{','}}}')将它们设置为{{{和}}};你现在必须使用它们来征求你的意见:

{{{-- {{link_to_route('language.select', 'English', array('en'))}} --}}}