ホーム > Laravel > How to comment out in Laravel blade
Laravel

How to comment out in Laravel blade

Thank you for your continued support.
This article contains advertisements that help fund our operations.

⇨ Click here for the table of contents for Laravel articles

This article summarizes how to comment out in Laravel blade.

What is a comment out?

It is something that is not displayed to users but remains as a note in the file.

For example,

<html>
  <!-- This text will not be displayed -->
</html>

It can be used like this.

How to comment out in Laravel Blade

In Laravel blade, you can comment out just like regular HTML.

test.blade.php

<html>
  <!-- This text will not be displayed -->
</html>

You can comment out exactly like an HTML file, so this should be fine most of the time.

How to comment out in parts dealing with data

When you comment out in parts dealing with data,

<html>
  <!-- {{ $post->title }} -->
</html>

$post->title will be retrieved but not displayed.

The next method is a way to not retrieve data (do not execute functions) in the first place.

{{-- $post->title --}}

By writing like this, you can comment out in a way that the functions usable in blade are not executed in the first place.

In other examples,

{{--
 @if($user)

 @endif
 --}}

You can prevent the execution of functions like @if in blade.

The benefit of this is that by not executing functions or retrieving data in the first place, you can avoid strange bugs or unnecessary processing.

Please take advantage of this.

Conclusion

That's all.

I hope it helps someone.

For feedback or complaints, please contact me on Twitter DM.

That's it!

Popular articles

Deploying a PHP 7.4 + Laravel 6 project to AWS EC2

Implementing breadcrumbs in Laravel with laravel-breadcrumbs

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!