29/12
2012
Lambda-based template system for PHP
Many years ago CoffeeKup was born, we have lots of template engines now., (*1)
Well, I made this just for the "why not?" and inspired by the Markaby pattern, actually less sexy on PHP., (*2)
Of course, shall be installed as dependency using the Composer., (*3)
Display your favorite books., (*4)
<?php require 'vendor/autoload.php'; $data = [ [ 'author' => 'Hernando de Soto', 'title' => 'The Mystery of Capitalism' ], [ 'author' => 'Henry Hazlitt', 'title' => 'Economics in One Lesson' ], [ 'author' => 'Milton Friedman', 'title' => 'Free to Choose' ], ]; # painless $view = function () { if ($books) { table(function () { tr(function () { th('Author'); th('Title'); }); foreach ($books as $key => $val) { tr(function () { td($val['author']); td($val['title']); }); } }); } else { p('There are no books to display.'); } }; # or using a clean render() helper... echo Puke\Base::render($view, ['books' => $data]); # now try this p('funny');
Note that a simple echo will not work as normally, use the text()
helper inside
the template to achieve the same result., (*5)
Eval is evil but seriously here he is the king., (*6)
There is not much to say, if you want contribute you're welcome buddy., (*7)