Reputation: 1242
Every developer writes comments in his HTML, CSS or Javascript. But I don't want my comments to be visible for other people. I develop an web app with laravel php framework and I want to clear all comments from my code as:
// comment
/* comment */
<!-- comment -->
I mean to clear the comments in runtime, so end-user to not see them in the web page source code. How can I do that?
Upvotes: 1
Views: 702
Reputation: 1242
Well, I found a solution, it's something that is called Blade Extending. So, how to use it for that purpouse? I will give you an example:
Blade::extend(function($value)
{
$value = preg_replace('/<!--(.+?)-->/s', '', $value); //it's removing <!-- multiline comments -->
$value = preg_replace('/\/\*(.*?)\*\//s', '', $value); //it's removing /* multiline comments */
$value = preg_replace('/(?<!:)\/\/.+/', '', $value); //it's removing // single line comments in JS
return $value;
});
You should place this code in non-public/app/filters.php or anywhere else, there is no matter, if it is executing before the view rendering.
I hope this will be useful for other people too.
Upvotes: 1
Reputation: 166066
It's unstated, but I assume you want a way to leave comments that aren't rendered in HTML?
If you're using PHP templates with Laravel, just use PHP comments
<?php // this is my comment ?>
If you're using the blade template engine, just use blade comments
{{-- This comment will not be in the rendered HTML --}}
Upvotes: 0