问题
I have migrated my app from laravel 4.2 to 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:
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:
\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');
but how can I add laravel 4 backward comparability for comments {{-- --}}
?
edit:
how to comment this in laravel 5:
<li {{ (Request::is('/') ? ' class="active"' : '') }}><a href="{{{ URL::to('') }}}">{{trans('messages.Home')}}</a></li>
回答1:
Since you change your content tags from {{
to {{{
comment tags are now {{{--
not {{--
回答2:
From 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.
{{-- 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 --}}}
回答3:
In general the comment syntax has not changed in Laravel 5, however...
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:
{{{-- {{link_to_route('language.select', 'English', array('en'))}} --}}}
来源:https://stackoverflow.com/questions/30217795/how-to-comment-code-in-blades-like-laravel-4