何もインストールする必要はありません。PHP で使用するだけです。テンプレートを読み込んでレンダリングする簡単なスクリプトを次に示します。
require_once( "Twig/Autoloader.php" );
Twig_Autoloader::register();
// Load template files from the ./tpl/ folder and use ./tpl/cache/ for caching
$twig = new Twig_Environment( new Twig_Loader_Filesystem("./tpl"),
array( "cache" => "./tpl/cache" ) );
// Load and render 'template.tpl'
$tpl = $twig->loadTemplate( "template.tpl" );
echo $tpl->render( array("msg"=>"Hello, World!") );
template.tpl は次のようになります。
<html>
<!-- ... -->
<body>
<h1>{{ msg|e }}</h1>
</body>
</html>
この例では、「Hello, World」をエスケープしてエコーします。
詳細については、(PHP) 開発者およびテンプレート デザイナー向けのドキュメントを参照してください。