How Can I Change The Blade Template File Extention From *.blade.php To Only *.blade

- 1 answer

I know Laravel's blade template resides in /resource/views directory. And it's extension is .blade.php .

My problem is I have set a separate repo for front end designer to work on blade template, and the repo is set restricted to push any file with an .php extension.

So what if I change all the .blade.php file to .blade file! By doing so laravel is unable to fine the view file.

How can I manage it.



You can easily add your custom extension, Laravel provides an easy way out of the box. Just open app\Providers\AppServiceProvider.php file and add the following code in the boot method (Don't forget to use use View at the top of the class after namespace App\Providers;):

public function boot()
    View::addExtension('blade', 'blade');

Now, you can use something like this, for example:

Route::get('/example', function () {
    return view('example', ['name' => 'The Alpha']);

In this case, you should create a view in views directory using name example.blade, for example (resources/views/example.blade):

<!-- Also a master.blade should be in views/layouts directory -->

    Hello {{ $name }}

This is the resources/views/layouts/master.blade code:

<!DOCTYPE html>
        <title>Laravel Custom Template</title>

If everything goes right then you should see Hello The Alpha when visiting the /example route. So, the only thing is to add a new extension using the View::addExtension('extension', 'engine), in this example, I've used blade as engine so you can use all the blade directives/syntax. Alternatively, you can use php as engine, these are available by default (also file) and if you use php as engine then you can't use blade directives/syntax.