Created
August 16, 2012 17:12
-
-
Save PetteriVaarala/3371759 to your computer and use it in GitHub Desktop.
Twig example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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