Jul 22, 2016

How Laravel Blade @include .html files

We can include a .html file instead of .php file with Laravel 5 Blade.

By default Blade engine looks for .blade.php files, and then falls back to .php files. We can do what we want by telling Laravel's view system to also consider .html files by adding .html to the searched extensions by adding the following somewhere in our bootstrapping code:

View::addExtension('html', 'php');

In certain project, we add this to the base controller to apply globally.

class Controller extends BaseController
    use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;

    function __construct() {
        // tells the view finder to look for `.html` files and run
        // them through the normal PHP `include` process
        View::addExtension('html', 'php');

No comments:

Post a Comment