Need help with jade.php?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

everzet
446 Stars 101 Forks MIT License 70 Commits 17 Opened issues

Description

HAML-like template engine for PHP 5.3 & Symfony2

Services available

!
?

Need anything else?

Contributors list

# 6,992
PHP
seleniu...
Sass
Symfony
70 commits

Jade - template compiler for PHP5.3

Jade is a high performance template compiler heavily influenced by Haml and implemented for PHP 5.3.

Features

  • high performance parser
  • great readability
  • contextual error reporting at compile & run time
  • html 5 mode (using the !!! 5 doctype)
  • combine dynamic and static tag classes
  • no tag prefix
  • clear & beautiful HTML output
  • filters
    • :php
    • :cdata
    • :css
    • :javascript
  • you even can write & add own filters throught API
  • TextMate Bundle
  • VIM Plugin

Public API

$dumper = new PHPDumper();
$dumper->registerVisitor('tag', new AutotagsVisitor());
$dumper->registerFilter('javascript', new JavaScriptFilter());
$dumper->registerFilter('cdata', new CDATAFilter());
$dumper->registerFilter('php', new PHPFilter());
$dumper->registerFilter('style', new CSSFilter());

// Initialize parser & Jade $parser = new Parser(new Lexer()); $jade = new Jade($parser, $dumper);

// Parse a template (both string & file containers) echo $jade->render($template);

Syntax

Line Endings

CRLF and CR are converted to LF before parsing.

Indentation

Jade is indentation based, however currently only supports a 2 space indent.

Tags

A tag is simply a leading word:

html

for example is converted to



tags can also have ids:

div#container

which would render

how about some classes?

div.user-details

renders

multiple classes? and an id? sure:

div#foo.bar.baz

renders

div div div sure is annoying, how about:

#foo
.bar

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:

input:text

will expand to

 & it's the same as 
input( type="text" )
, but shorter. Another examples:
input:submit( value="Send" )

will become

.

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 (

input:email
=>
).

Tag Text

Simply place some content after the tag:

p wahoo!

renders

wahoo!

.

well cool, but how about large bodies of text:

p
  | foo bar baz
  | rawr rawr
  | super cool
  | go Jade go

renders

foo bar baz rawr.....

Actually want

 for some reason? Use 
{{}}
instead:
p {{$something}}

now we have

Nesting

ul
  li one
  li two
  li three

Attributes

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:

input(type="checkbox", checked)

Boolean attributes with code will only output the attribute when

true
:
input(type="checkbox", checked: someValue)

Note: Leading / trailing whitespace is ignore for attr pairs.

Doctypes

To add a doctype simply use

!!!
followed by an optional value:
!!!

Will output the transitional doctype, however:

!!! 5

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' => ''
   );

Comments

Jade Comments

Jade supports sharp comments (

//- COMMENT
). So jade block:
//- JADE
- $foo = "

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.