webman: 使用模板引擎twig
一,安装
$ composer require twig/twig
二,配置
config/view.php
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use support\view\Twig;
return [
'handler' => Twig::class,
'options' => [
'debug' => false,
'charset' => 'utf-8'
]
];
三,例子
php
<?php
namespace app\controller;
use support\Request;
class LoginController
{
public function index(Request $request)
{
return response(__CLASS__);
}
public function login(Request $request) {
$data = ['name' => '老刘'];
return view('login/login', $data);
}
}
模板:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<header></header>
<main>
hello {{name}}
</main>
<footer></footer>
</body>
</html>
四,测试效果: