Slade

A PHP templating engine inspired by both Ruby Slim and Laravel Blade

Example

The following template

doctype html
html
  head
    title Slade
    link href="style.css"

  body
    h1 My first Slade template!

    ? name
      p
        | Hello {{name}}, this line only appears
        | if the name variable contains a truthy.

    ! name
      p There is no name.

    h2 Here is a list of names of people:
    ul
      > people
        li = person.name

Could parse into the following HTML:

<!DOCTYPE html>
<html>
  <head>
    <title>Slade</title>
    <link href="style.css">
  </head>

  <body>
    <h1>My first Slade template!</h1>

    <p>
      Hello John Doe, this line only appears
      if the name variable contains a truthy.
    </p>

    <h2>Here is a list of names of people:</h2>
    <ul>
      <li>Harry</li>
      <li>Ron</li>
      <li>Hermione</li>
    </ul>
  </body>
</html>

You can also extend another template this way:

_ layouts.default
  @ content
    p This paragraph will be assigned to the 'content' section

Which will then extend for example layouts/default.slade and the paragraph will appear wherever the following line is included in layouts/default.slade:

- content

Installation

Use

composer require evertt/slade

to include this package into your project. Note, this package requires PHP 5.5. If you want to use it with Laravel, then in config/app.php add 'Slade\SladeServiceProvider' to your list of service providers. If you want to use this package independently from Laravel, then just make sure you set Slade::$templatePaths to an array of the paths to the root folder of your templates.

So if you set:

Slade::$templatePaths = ['/my-project/views', '/my-project/some-vendor/views'];

And you ask Slade to parse the view users.index then it will first look for the file /my-project/views/users/index.slade and if that doesn't exist it will look for /my-project/some-vendor/views/users/index.slade.

Usage

To use this engine in your controller for example, simply put

use Slade\Slade;

at the top of your controller file and then in any action use:

return Slade::parse('users.index', compact('user'));

Check the wiki for more information.