Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created December 21, 2012 11:45
Show Gist options
  • Save mattattui/4352331 to your computer and use it in GitHub Desktop.
Save mattattui/4352331 to your computer and use it in GitHub Desktop.
Sample Twig setup and template
<?php
require __DIR__.'/../vendor/autoload.php';
$loader = new Twig_Loader_Filesystem(__DIR__.'/../templates');
$twig = new Twig_Environment($loader, array(
// Uncomment the line below to cache compiled templates
// 'cache' => __DIR__.'/../cache',
));
$name = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
if (!$name) {
$name = "Mercury, Venus, Mars, Jupiter, Saturn, Uranus & Neptune.";
}
echo $twig->render('index.twig', array(
'name' => $name,
));
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Twig test</title>
</head>
<body>
<h1>Hello world</h1>
<p>And hello {{ name }}</p>
</body>
</html>
@craigiswayne
Copy link

Helpful :) thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment