Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Introduction to JadePHP
Apr 10, 2014 @ 15:30:30

Lukas White has posted an introduction to JadePHP to the SitePoint PHP blog today. JadePHP is a port of the popular Jade templating language more often used in Javascript.

There are dozens of templating engines out there, with options such as Smarty, Twig (used in the upcoming version of Drupal) and Blade (the default for Laravel) among the best known – as well as vanilla PHP, of course. [...] One which differs quite significantly from most is Jade, an engine usually associated with Javascript applications – it’s supported out-of-the-box by Express for Node.js, for example. It’s Jade I’m going to look at in this article; or more specifically the PHP port JadePHP.

He starts by briefly talking about HAML, a markup language that aims to make it easier and cleaner to write well-formatted HTML documents. Jade creates the entire document this way, meaning you could use it even without any templating needs (just outputting normal HTML pages). He shows you how to get started with the code and provides a simple example of a basic HTML page without any template objects to replace.He explains the markup and what each part does before moving on and showing how to add in the dynamic content and logic. He finishes off the tutorial by answering the question "Why use Jade?" touching on some of the good and bad of the templating engine.

tagged: jadephp templating haml markup library tutorial

Link: http://www.sitepoint.com/introduction-jadephp

Sameer Borate's Blog:
Templating with Haml
Sep 09, 2010 @ 17:51:40

Sameer Borate has posted about an alternative templating system that's currently being used in multiple languages - Haml (HTML Abstraction Markup Language). As Sameer points out, there's also a PHP port of it.

It has been a while since I’ve used a template engine during development, the last one I used was Smarty. Now there are a plethora of template systems, but most are a rehash of Smarty. Readers may beg to differ, but Smarty gets the work done, which is all that matters. The one that I found really interesting is Haml.

He includes some markup examples of how it's structured - the main structure of the site, tables, divs, etc - and what it comes out like on the other side of the parser. The phphaml and phamlp libraries let you run the template through with variable values set and display it. There are some downsides he mentions, though, like the rules on indentation and that the markup has to be all in one file (or combined before sending to be rendered).

tagged: template haml markup abstraction tutorial phphaml phamlp

Link:


Trending Topics: