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
Laravel Blade @include .html files
提问by Dirk Jan
Include HTML files with blade
使用刀片包含 HTML 文件
Can I include a .html
file in stead of .php
with Laravel 4 Blade?
我可以包含一个.html
文件来代替.php
Laravel 4 Blade 吗?
My code:
我的代码:
@include('emails.templates.file')
//file is email.html
file
is automatically a .php
file..
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 .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:
但是,您可以通过告诉 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.
让我知道它是否仍然是一个问题。