Loading a laravel view with .html extension

半城伤御伤魂 提交于 2019-12-23 08:28:48

问题


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

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.

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


回答1:


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

Here's my code sample:

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);
        }
    }
}



回答2:


I am afraid Blade engine loads .php and .blade.php files only.

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



来源:https://stackoverflow.com/questions/20955571/loading-a-laravel-view-with-html-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!