且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel Blade @include .html文件

更新时间:2023-02-26 07:56:12

虽然@ PHPWeblineindia的解决方案为您工作,但它并不是真正的Laravel方式。然而,

然而, ,你可以通过告诉Laravel的视图系统也考虑 .html 文件来做你想做的事情。默认情况下,它会查找 .blade.php 文件,然后返回到 .php 文件。您可以通过在您的引导代码中添加以下内容将 .html 添加到搜索的扩展中:

  //告诉视图查找器寻找`.html`文件并运行
//通过普通的PHP include包处理$ b $ View :: addExtension('html', 'PHP');

这实际上将HTML视为最高优先级,因此请确保您没有两个不同的视图用不同的扩展名称来称呼相同的东西。


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..

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.