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'); // 拡張子は記述しない
});