加载带有 .html 扩展名的 Laravel 视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20955571/
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 08:50:47  来源:igfitidea点击:

Loading a laravel view with .html extension

laravellaravel-4

提问by Mcg1978

Is it possible to have Laravel load view templates with a .html extension?

是否可以让 Laravel 加载带有 .html 扩展名的视图模板?

I'm rebuilding an existing app that has a bunch of .html files that are uploaded by users. It's a sort of multi-tenant application where each user can control the look and feel of their area by uploading templates.

我正在重建一个现有的应用程序,其中包含一堆由用户上传的 .html 文件。这是一种多租户应用程序,每个用户都可以通过上传模板来控制其区域的外观。

I need to rebuild the app and make the change completely transparent to the users so I'd like to keep the .html extensions.

我需要重建应用程序并使更改对用户完全透明,因此我想保留 .html 扩展名。

回答by Peter Drinnan

The best way I have found is to use View::addExtension in your base controller;

我发现的最好方法是在您的基本控制器中使用 View::addExtension;

Here's my code sample:

这是我的代码示例:

View::addExtension('blade.html','blade');

View::addExtension('blade.html','blade');

class BaseController extends Controller {

    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */
    protected function setupLayout()
    {

        // Allows us to use easy-to-edit html extension files.
        // You can set 2nd param to 'php' is you want to 
        // just process with php (no blade tags)
        View::addExtension('blade.html','blade');


        if ( ! is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }
}

回答by Andreyco

I am afraid Blade engine loads .phpand .blade.phpfiles only.

恐怕只有刀片引擎加载.php.blade.php文件。

From your description I assume the view files are static, since they are HTML only. If so, rename them to .phpafter user uploads view files - should not bring performance impact to your application, since there is nothing to process anyway.

根据您的描述,我假设视图文件是静态的,因为它们只是 HTML。如果是这样,请.php在用户上传视图文件后将它们重命名为- 不应给您的应用程序带来性能影响,因为无论如何都不需要处理。