2017 © Pedro Peláez
 

library neddle

The most simple templating engine for PHP

image

habanero/neddle

The most simple templating engine for PHP

  • Friday, April 26, 2013
  • by pateketrueke
  • Repository
  • 2 Watchers
  • 1 Stars
  • 151 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Tailor's skills!

Neddle is inspired from HAML/Jade and CoffeeScript, isn’t really a full parser but it handles your templates very well., (*1)

Ok, it might have issues and do not throw any warnings about syntax errors., (*2)

The basics

Like other haml-like templating engines, it uses white space to nest your blocks. Also has minimal support for inline expressions, closures and almost all php code., (*3)

inline-comments, (*4)

/ html
- # php
; invisible

block-comments, (*5)

/
  large and
  nested html comments

html-blocks, (*6)

#id.class { attr => $value }
  a { href => '#' } link text

p
  nested text
  here

pre
  |and the pipe
  |    preserves the white-space
  | in the block

<table>
  <tbody>
    <tr>
      <td>also you can use raw html</td>
    </tr>
  </tbody>
</table>

<?php echo 'and raw php code'; ?>

\a string value (not parsed)
a string value (parsed)

:some-filter
  any block of text (not parsed)

php-blocks, (*7)

- if $condition
  = 'success'

ul
  - for $i = 0; $i < 10; $i += 1
    li = "Item $i"

- $all = array(1, 2, 3)
p #{$one} @while $one = array_shift($all)

- unless false
  some text

- print_r(call_user_func(~>
  - return range(0, 10)

- $lambda = ($value) ~>
  - return $value

= $lambda('some value')
~ $lambda('<p>escaped text</p>')

As you can see the syntax is very simple and compatible with php. ;-), (*8)

Usage

Append it to your composer.json, then run $ php composer.phar install to get the latest version., (*9)

{
  "require": {
    "habanero/tailor": "dev-master"
  }
}

Remember that neddle will not handle your views, it only pre-compile your templates into php code. You should save and execute the produced code., (*10)

<?php

require 'vendor/autoload.php';

# raw handling
$tpl = 'a { href => "#" } = "link"';
$out = Neddle\Parser::render($tpl);

eval('; ?' . ">$out"); // <a href="#">link</a>


# using as helper
function view($file, array $vars = array()) {
  ob_start();

  $tpl = file_get_contents($file);
  $_tpl = tempnam('/tmp', md5($file));
  file_put_contents($_tpl, Neddle\Parser::render($tpl));

  extract($vars);
  require $_tpl;
  unlink($_tpl);

  $out = ob_get_clean();

  return $out;
}


# full-view rendering
$tpl = 'example.neddle';
$out = view($tpl, array('name' => 'Joe'));

echo $out; // <p>Hello Joe!</p>

And this is the source for the example.neddle file., (*11)

p = "Hello $name!"

Want to collaborate?

If you like, fork, download and use it., (*12)

The Versions

26/04 2013

dev-master

9999999-dev

The most simple templating engine for PHP

  Sources   Download

The Requires

  • php >=5.3

 

by Alvaro Cabrera

26/04 2013

v0.3.1

0.3.1.0

The most simple templating engine for PHP

  Sources   Download

The Requires

  • php >=5.3

 

by Alvaro Cabrera