问题
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