Laravel – Blade comments , blade rendering causing page to crash

Blade comments should only be used for simple remarks or to comment out single-line Blade functions. A single Blade comment cannot be used to comment out multiple lines of code.


Use PHP Block Comments instead. They are still usable in a blade.php file

<?php /* 
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
*/ ?> 

Alternatively, comment out your Blade one line at a time:

{{-- HTML::form("foo") --}};
{{-- HTML::form("bar") --}};

Examples of Valid Blade Comments:

Single Blade Function:

{{-- Form::text('foo') --}}

Remark:

{{-- Form Section 1 --}}

Examples of Invalid Blade Comments:

Incorrect syntax:

{{-- Form::text('foo') --  }} 

“@” Inside of Blade comment

{{-- @Form::text('foo') --}} 

Nested PHP:

{{-- <?php 
echo "foo";
echo "bar
?> --}} 

Nested Blade:

{{-- 
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
--}} 

Internals:

Using the sample code from the question, Laravel’s Blade Compiler will generate a temporary PHP file containing the following PHP and HTML:

<?php /* 
    <div class="form-row">
      <?php echo Form::label('foo', 'foo:'); ?>

<?php echo Form::text('foo'); ?>

</div>
<div class="form-row">
    <?php echo Form::label('foo', 'foo:'); ?>

    <?php echo Form::text('foo'); ?>

</div>
<div class="form-row">
    <?php echo Form::label('foo', 'foo'); ?>

    <?php echo Form::text('foo'); ?>

</div>
*/ ?>

The Blade code inside of the Blade comments are still parsed into PHP. The PHP end tags inside of the PHP block-comment can cause compilation issues:

?> breaks out of PHP mode and returns to HTML mode, and // or #
cannot influence that.

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.