eccube3で、手軽にControllerにて$app変数を作成しtwigに反映させる
2021年5月28日ここではsrc/Eccube/Controllerディレクトリ内の
ProductController.phpにて、$app[“test”]という変数を作成します。
public function index(Application $app, Request $request){
}
の中に、以下のように記述します。
public function index(Application $app, Request $request){
$app[“test”]=”Hello Test”;
}
と記述します。
その後、list.twigにて
{% block main %}
の直下に
{{ app.test }}
と記述することで、「Hello Test」の文字がtwigにて表示できます。