Skip to content

Instantly share code, notes, and snippets.

@jakemcgraw
Created April 19, 2011 20:10
Show Gist options
  • Save jakemcgraw/929494 to your computer and use it in GitHub Desktop.
Save jakemcgraw/929494 to your computer and use it in GitHub Desktop.
The hurdur templating engine for PHP
# hurdur.php
<?php
function hurdur_render($_template, array $params=array()) {
if (isset($params['_template'])) {
trigger_error('_template is reserved');
}
extract($params);
include $_template;
}
function hurdur_partial($template, array $collection) {
foreach($collection as $params) {
hurdur_render($template, $params);
}
}
?>
# index.php
<?php
include 'hurdur.php';
hurdur_render('index.phtml', array('collection' => array(array('name' => 'Jake'), array('name' => 'Jorge'))));
?>
# index.phtml
<!DOCTYPE html>
<html>
<body>
<h1>My Site</h1>
<?php if (!empty($collection)) : ?>
<ul>
<?php hurdur_partial('user.phtml', $collection) ?>
</ul>
<?php endif ?>
</body>
</html>
# user.phtml
<li><?php echo $name ?></li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment