メインメニュー
XAMPP アレンジ
IED
WSL2
-
道具箱
リポジトリ編
フレームワーク編
公開ソフトウェア
メタ
リンク
- PHP ライブラリ
- PHP 言語
basic-library:bladeone:3.37テンプレートエンジン - BladeOne
Version 3.37 (MIT License)
— y2sunlight 2020-03-11
関連記事
- テンプレートエンジン - BladeOne
リンク
- https://github.com/EFTEC/BladeOne — BladeOneの本家
- https://laravel.com/docs/5.8/blade — laravel5.8のblade (英語)
- https://readouble.com/laravel/5.8/ja/blade.html — laravel5.8のblade (日本語)
- https://blog.hiroyuki90.com/articles/laravel-blade/ — Laravel blade テンプレートの使い方まとめ
テストプログラムの所在
{Project Folder}\test\
bladeoneについて
BladeはLaravelに標準搭載されているテンプレートエンジンです。本編で使用するbladeoneは、Laravelをインストールしなくても単独で使用できるようにした、いわばBladeのスタンドアロン版です。
本編でのテンプレートエンジンの選定基準は「環境設定、ログ出力とテンプレートエンジンはいつも使っているフレームワークと同じ」なので、Laravel常用者の筆者としては、ここは迷うことなくbladeoneに決めましたが、他のテンプレートエンジンをでも全く問題ありません。要は、手持ちのテンプレート資産がそのまま利用できれば良いだけです。
インストール
composer require eftec/bladeone
Using version ^3.37 for eftec/bladeone ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing eftec/bladeone (3.37): Downloading (100%) Writing lock file Generating autoload files 1 package you are using is looking for funding. Use the `composer fund` command to find out more!
Note:
Eclipse起動中にパッケージを取得した場合は、プロジェクト・エクスプローラー内の[プロジェクト(apricote)]を右クリックして[リフレッシュ]を選択して下さい。また、新しく取得したパッケージのインテリセンスが有効にならない場合は、プロジェクトのビルトまたはクリーン&ビルドを行ってビルドリストの更新を行って下さい。パッケージの取得が終わると
composer.json
のrequire
に以下が追加されます。- composer.json
{ "require": { "eftec/bladeone": "^3.37" } }
テストプログラム
パッケージのテストフォルダ(
test\
)に、テスト用のコード(bladeone.php
)とテンプレートファイル(hello.blade.php
)を作成します。以下の例では、テンプレートはtest\views\
に設置し、キャッシュはview\cache
に作成されます。- bladeone.php
<?php require __DIR__.'/../vendor/autoload.php'; Use eftec\bladeone\BladeOne; // 初期化 $views = __DIR__.'/views'; // テンプレートパス $cache = __DIR__.'/var/cache'; // キャッシュパス(コンパイル済ファイル) $blade = new BladeOne($views,$cache,BladeOne::MODE_AUTO); // テンプレート変数 $variables = ["variable1"=>"Hello", "variable2"=>"World", ]; // レンダリング echo $blade->run("hello", $variables);
- hello.blade.php
<h1>Title</h1> {{$variable1}},{{$variable2}}!!
実行結果
Title Hello,World!!
basic-library/bladeone/3.37.txt · 最終更新: 2020/04/18 10:51 by y2sunlight
コメント