以下是我第一支 php + twig 程式,在 MS-Windows + Xampp 的環境
<?php
//載入 Twig
require_once './Twig/Autoloader.php';
Twig_Autoloader::register();
//設定 Templates 目錄 loads templates from the file system.
$loader = new Twig_Loader_Filesystem('./Templates');
$twig = new Twig_Environment($loader);
// 指定樣板
$template = $twig->load('text.html');
// 輸出資料,方法一:給予render
echo $template->render ( array (
'Name' => 'Kevin Wang'
));
// 輸出資料,方法二
echo $twig->render( 'text.html', array(
'Name' => 'Kevin Wang'
));
?>
沒有留言:
張貼留言