I am running Mamp as my local server & I Have installed Twig here: /Applications/MAMP/svn/twig/twig/lib. I have included this path in my php.ini file (include_path = ".:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/svn/zendframework/trunk/library:/Applications/MAMP/svn/twig/twig/lib" ;) What needs to go in my htdocs folder in order to complete the installation & access twig?
A:
You don't need to install anything, you can just use it in PHP. Here's a simple script to load and render a template:
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!") );
Your template.tpl could look like this:
<html>
<!-- ... -->
<body>
<h1>{{ msg|e }}</h1>
</body>
</html>
This example will just escape and echo "Hello, World".
For more information just read the documentation for (PHP) developpers and template designers.
svens
2010-08-09 00:13:22
Thanks this helps clear up some things.
demet8
2010-08-09 13:45:57