6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel 4 Viewテンプレートファイルの拡張子を追加する

Last updated at Posted at 2014-09-22

Laravel 4 では、View::make() で読み込むテンプレートファイルは、拡張子が .php.blade.php になっています。

下記のように、View::make() に直接、拡張子を追加すると、data.js.php というファイルではなく、フレームワークが ./ に置換するため、data/js/php.(php|blade.php)として解釈されます。

Route::get('/', function() {
    return View::make('data.js.php');
});

独自の拡張子を利用したい場合は、View::addExtension() を使って、テンプレートファイルの拡張子として認識させます。

下記では、js.php という拡張子のファイルを PHP ファイルとして扱うように指定しています。

View::addExtension('js.php', 'php'); // js.php という拡張子を、PHP として扱う

Route::get('/', function() {
    return View::make('data'); // 拡張子は記述しない
});
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?