Posts by

Luke Watts

Luke Watts

Founder of Affinity4.ie, a Galway-based web development agency.

Author of Mastering Sass (Packt Publishing), master Sass and Susy to build responsive enterprise-level user interfaces and web applications.

Oracle Certified Professional MySQL 5.0 Database Developer with PHP 5.4+.

Certified FETAC Level 6 Trainer.

Galway, Ireland luke-watts.com 8 posts

Creating a Simple Template Engine with PHP: Part 2

Creating a Simple Template Engine with PHP: Part 1

In the last part we covered setting up our project and getting our Engine::render() method to render our view file and interpolate the variables passed into it. Already it is more useful that using PHP on it's own to display pages. However, we want more than that. We want to eventually be able to have a new syntax for out variables, loops and conditional statements.

Why you should use Silex for you next project

Almost a year ago now I worked on a contract where I was required to convert legacy PHP code, which had been written by a non-programmer. For the refactoring I first redesigned the database entirely, refactored any of the business logic out of any files which rendered content, and organised the entire structure. I created a simple router which was used to map simple urls to views which where rendered using an output buffer. I then set about finding an MVC framework to incrementally integrate with the refactored app.

After a few days of research, I chose Silex. Silex is very minimal and unopinionated. It also has very good documentation, including how to add Twig, the Doctrine DBAL (the ORM takes a bit of work) and many of the Symfony packages (Monolog, Swiftmailer, Session, Serializer, Assets and more). The best part was I could use Silex on it's own initially while moving my existing code to routes and controllers, and only then add a template engine and DB library. It also allows you to decide the structure yourself. As the project evolved I was able to rework anything that required it and add any library that could be PSR autoloaded easily.

Moving to Postleaf

I've been using WordPress for about 5 years. It's been my go to CMS for too long. All of last year I wanted to move away from using WordPress and start using a more modern CMS for my personal site. WordPress has horrible code, poor release integrity, and all too frequent security issues. When the 4.7.2 release caused my website to be immediately compromised I know it was time to look for more options. So I looked at Drupal8, Concrete5 and more recently Grav and BoltCMS as possible alternatives. Each had varying strengths and weaknesses.

Drupal8 was rebuilt to use most of the agreed upon PHP best practices such as PSRs, Composer, Twig templates and YAML config files. This is great but the admin area is still horrible and too much needs to be done in .yml files. Every modules, theme and Drupal itself has at least one .yml file which needs to be modified to work. For me this was too much of a learning curve to commit to at the time. I know an easier solution must be out there.

My First Book Mastering Sass is Out Now!

My very first book was published in late August 2016. The book Mastering Sass is published by Packt Publishing and is available in ebook (PDF, Mobi, Kindle) format or print.

It covers advanced Sass, Compass and Susy techniques to create responsive, data-intensive web applications such as e-commerce websites, news websites or anything else.