Laravel Blade @include .html files
22,202
Solution 1
While @PHPWeblineindia's solution worked for you, it's not really the Laravel way.
However, you can do what you want by telling Laravel's view system to also consider .html
files. By default it looks for .blade.php
files, and then falls back to .php
files. You can add .html
to the searched extensions by adding the following somewhere in your bootstrapping code:
// tells the view finder to look for `.html` files and run
// them through the normal PHP `include` process
View::addExtension('html', 'php');
This will actually put HTML as the highest priority, so make sure you don't have two different views called the same thing with different extensions.
Solution 2
If its an external file then can you please try this:
<?php include app_path() . '/views/<path_to_layout/emails>/file.html'; ?>
Let me know if its still an issue.
Comments
-
Dirk Jan almost 2 years
Include HTML files with blade
Can I include a
.html
file in stead of.php
with Laravel 4 Blade?My code:
@include('emails.templates.file') //file is email.html
file
is automatically a.php
file.. -
Peter Drinnan about 9 yearsYou can also add this to the base controller to apply globally.
-
alexrussell about 9 yearsTrue but I'd suggest in the application bootstrapping code (or a service provider, which is pretty much the same thing) rather than in a base controller just in case.
-
C.Liddell about 8 years@alexrussell What do you mean by bootstrapping code and where would that be located at in Laravel? I am fairly new to Laravel running Laravel 5.2 and I've tried adding
View::addExtension
to my BaseController inside the protected methodsetupLayout()
. The result of this is when trying to use include, Laravel simply returnsView [view.name] not found
where view.name has an.html
extension. -
alexrussell about 8 yearsBased on the timing of my original answer, it was actually more geared to Laravel 4.2. However, application bootstrapping code is kinda universal - basically any code that runs before most of the rest. In L4.2 the standard (albeit dirty) way was to put it in the routes file. Since L5, we've have the service providers, so maybe the AppServiceProvider, or, ideally, new service provider that does the required view changes. That said, I don't know if the original
View::addExtension()
call still stands in L5. -
C.Liddell about 8 years@alexrussell Thanks for the help anyway. I'll open up a new question specific to Laravel 5, I do not believe that
View::addExtension()
works any longer. -
C.Liddell about 8 yearsI was mistaken earlier.
View::addExtension()
does indeed work I just never called thesetupLayout()
method from within the controller. None the less if it helps anyone else, the new question is located here. -
Prashant Pokhriyal over 6 years@C.Liddell where I've to call
setupLayout()
method?