1

Mamp をローカル サーバーとして実行しています。Twig を にインストールしました/Applications/MAMP/svn/twig/twig/lib。このパスを php.ini ファイルに含めました。

include_path = ".:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/svn/zendframework/trunk/library:/Applications/MAMP/svn/twig/twig/lib";

インストールを完了して Twig にアクセスするには、htdocs フォルダーに何を入れる必要がありますか?

4

2 に答える 2

13

何もインストールする必要はありません。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) 開発者およびテンプレート デザイナー向けのドキュメントを参照してください。

于 2010-08-09T00:13:22.063 に答える
0
include __DIR__ . "/vendor/twig/twig/lib/Twig/Autoloader.php";  

//register autoloader  

Twig_Autoloader::register();  

//loader for template files  

$loader = new Twig_Loader_Filesystem('templates');  

//twig instance  

$twig = new Twig_Environment($loader, array('cache' => 'cache'));  

//load template file  

$template = $twig->loadTemplate('index.html');  

//render a template  

echo $template->render(array('title' => 'Welcome to Twig template'));  

このチュートリアルの詳細を見つける

于 2014-10-16T20:12:56.360 に答える