HAML-like template engine for PHP 5.3 & Symfony2
Jade is a high performance template compiler heavily influenced by Haml and implemented for PHP 5.3.
// Initialize parser & Jade $parser = new Parser(new Lexer()); $jade = new Jade($parser, $dumper);
// Parse a template (both string & file containers) echo $jade->render($template);
CRLF and CR are converted to LF before parsing.
Jade is indentation based, however currently only supports a 2 space indent.
A tag is simply a leading word:
for example is converted to
tags can also have ids:
which would render
how about some classes?
multiple classes? and an id? sure:
div div div sure is annoying, how about:
which is syntactic sugar for what we have already been doing, and outputs:
jade.php has a feature, called "autotags". It's just snippets for tags. Autotags will expand to basic tags with custom attributes. For example:
will expand to& it's the same as
input( type="text" ), but shorter. Another examples:
input:submit( value="Send" )
You can even add you own autotags with:
$parser->setAutotag('input:progress', 'input', array('type'=>'text', class=>'progress-bar'));
that will expands to.
It also supports new HTML5 tags (
Simply place some content after the tag:
well cool, but how about large bodies of text:
p | foo bar baz | rawr rawr | super cool | go Jade go
foo bar baz rawr.....
Actually wantfor some reason? Use
now we have
ul li one li two li three
Jade currently supports '(' and ')' as attribute delimiters.
a(href='/login', title='View login page') Login
Alternatively we may use the colon to separate pairs:
a(href: '/login', title: 'View login page') Login
Boolean attributes are also supported:
Boolean attributes with code will only output the attribute when
input(type="checkbox", checked: someValue)
Note: Leading / trailing whitespace is ignore for attr pairs.
To add a doctype simply use
!!!followed by an optional value:
Will output the transitional doctype, however:
Will output html 5's doctype. Below are the doctypes defined by default, which can easily be extended:
$doctypes = array( '5' => '', 'xml' => '', 'default' => '', 'transitional' => '', 'strict' => '', 'frameset' => '', '1.1' => '', 'basic' => '', 'mobile' => '' );
Jade supports sharp comments (
//- COMMENT). So jade block:
//- JADE - $foo = "