Skip to content


Laravel - Blade comments , blade rendering causing page to crash

 

The solution is to only use Blade comments for simple remarks, or to comment out single-line Blade functions. Do not nest Blade/PHP code inside of Blade comments. Use standard PHP block comments to comment out multiple lines of code within a single comment (PHP, HTML, multiple blade functions, etc.).


Valid Blade Comments:

Single Blade Function:

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

Remark:

{{-- Form Section 1 --}}

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") }};
--}} 

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") --}};

Internals:

For the OP’s code, Laravel’s Blade Compiler will generate a temporary PHP file containing the following PHP/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 inside of your Blade comments are still being parsed into PHP. The PHP end tags inside of the PHP block-comment is causing the Apache’s parser to end early, resulting in some badly-formed PHP/HTML that could be crashing your connection (likely caused by the dangling */ ?>).

Posted in Laravel. Tagged with , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.