Recently I’ve been using the TWIG php templating engine for a large project. I hadn’t used a dedicated php templating engine since Smarty and had persuaded myself that they were pretty much redundant of the needs of creating sites and apps these days since, perhaps with the advent of websites becoming so front-end-heavy, most ‘web-designers’ are savvy and knowledgeable enough to understand where php tags start and end.
However with a work spec. suggesting the use of one I tried it and I’m pleasantly surprised, and have decided that perhaps with something like TWIG in the stack adding some nice shorthand here and there there’s definitely a place for it.
I’ll leave you to find out more, I just felt like singing it’s praises slightly! As the twig documenation will tell you, it’s fast, secure and flexible.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php /* TWIG code snippet proof of concept. Some comments left in so you can see alternative use/syntax - rob ganly */ // $twigEnginePath = '/Applications/MAMP/bin/php5/lib/php/Twig/'; $twigEnginePath = '/Library/WebServer/Documents/blah/library/Twig/'; $twigTemplatePath = '/Library/WebServer/Documents/blah/application/layouts/scripts/TwigTemplates/'; $twigCachePath = $twigTemplatePath."compilationCache/"; require_once "$twigEnginePath/Autoloader.php"; // register the twig autoloader Twig_Autoloader::register(); // $loader = new Twig_Loader_String(); // $twig = new Twig_Environment($loader); $loader = new Twig_Loader_Filesystem($twigTemplatePath); //$twig = new Twig_Environment($loader, array('cache'=>$twigCachePath)); $twig = new Twig_Environment($loader); $template = $twig->loadTemplate('listview.html'); $docdatajson = '[{"title":"Mr","firstname":"Rob","surname":"Ganly","function":"test"}]'; $docdata = json_decode($docdatajson, true); $template->display(array( 'pageTitle'=>'Data List Test View', 'docs'=>$docdata )); |






