Laravel Blade @include .html 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26377352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:16:35  来源:igfitidea点击:

Laravel Blade @include .html files

htmllaravelviewincludeblade

提问by Dirk Jan

Include HTML files with blade

使用刀片包含 HTML 文件

Can I include a .htmlfile in stead of .phpwith Laravel 4 Blade?

我可以包含一个.html文件来代替.phpLaravel 4 Blade 吗?

My code:

我的代码:

@include('emails.templates.file')
  //file is email.html

fileis automatically a .phpfile..

file自动是一个.php文件..

回答by alexrussell

While @PHPWeblineindia's solution worked for you, it's not really the Laravel way.

虽然@PHPWeblineindia 的解决方案对您有用,但它并不是真正的 Laravel 方式。

However, you can do what you want by telling Laravel's view system to also consider .htmlfiles. By default it looks for .blade.phpfiles, and then falls back to .phpfiles. You can add .htmlto the searched extensions by adding the following somewhere in your bootstrapping code:

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

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

这实际上会将 HTML 作为最高优先级,因此请确保您没有两个不同的视图,它们被称为具有不同扩展名的同一事物。

回答by PHP Team

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.

让我知道它是否仍然是一个问题。