Skip to content

Instantly share code, notes, and snippets.

@PetteriVaarala
Created August 16, 2012 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetteriVaarala/3371759 to your computer and use it in GitHub Desktop.
Save PetteriVaarala/3371759 to your computer and use it in GitHub Desktop.
Twig example
<?php
require_once 'Twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_Environment($loader);
$navigation = array(
array('title' => 'Quake',
'alpha' => array('qwe', 'rty', 'uiop')
),
array('title' => 'Doom',
'alpha' => array('asd', 'fgh')
),
array('title' => 'Duke Nukem',
'alpha' => array('zx', 'cv', 'bn', 'm')
)
);
$data = array('title' => 'Whoosh',
'heading' => 'Foosh',
'navigation' => $navigation
);
$twig->display('index_view.html', $data);
//print_r($data);
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<h1>{{heading}}</h1>
{% for item in navigation %}
<b>{{ item.title }}</b>
{% for subitem in item.alpha %}
<li>{{ subitem }}</li>
{% endfor %}
{% endfor %}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment