Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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'); // 拡張子は記述しない
});
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away