Laravel Blade @include .html文件 [英] Laravel Blade @include .html files

查看:657
本文介绍了Laravel Blade @include .html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用刀片包含HTML文件



我可以包含 .html 文件而不是<$ c $我的代码:

  @include('emails.templates.file')
//文件是email.html

文件自动为 .php 文件。

解决方案

虽然@ 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.

这篇关于Laravel Blade @include .html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆