PHPackages                             clthck/slimphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. clthck/slimphp

ActiveProject[Templating &amp; Views](/categories/templating)

clthck/slimphp
==============

Ruby's Slim-like template engine for PHP 5.4+

v0.0.5(10y ago)389MITPHPPHP &gt;=5.4.0

Since Dec 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/clthck/slimphp)[ Packagist](https://packagist.org/packages/clthck/slimphp)[ RSS](/packages/clthck-slimphp/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (6)Used By (0)

SlimPHP - template compiler for PHP 5.4+
========================================

[](#slimphp---template-compiler-for-php-54)

*SlimPHP* is a high performance template compiler heavily influenced by [Slim](http://slim-lang.com), which is implemented for PHP 5.4 or greater.

Features
--------

[](#features)

- high performance parser
- great readability
- contextual error reporting at compile &amp; run time
- HTML5 mode (using the *doctype html*)
- combine dynamic and static tag classes
- no tag prefix
- clear &amp; beautiful HTML output
- filters
    - :php
    - :cdata
    - :css
    - :javascript
- you even can write &amp; add own filters throught API

Public API
----------

[](#public-api)

```
$dumper = new PHPDumper([
	'tabSize' => 4					// Tab size for output. Default value: 2
]);
$dumper->registerVisitor('tag', new AutotagsVisitor());
$dumper->registerFilter('javascript', new JavaScriptFilter());
$dumper->registerFilter('cdata', new CDATAFilter());
$dumper->registerFilter('php', new PHPFilter());
$dumper->registerFilter('css', new CSSFilter());

// Initialize parser & SlimPHP
$parser = new Parser(new Lexer([
	'tabSize' => 2					// Tab size for input. Default value: 2
]));
$slim   = new SlimPHP($parser, $dumper);

// Parse a template (either filename or content string)
echo $slim->render($template);

```

Syntax
------

[](#syntax)

### Line Endings

[](#line-endings)

**CRLF** and **CR** are converted to **LF** before parsing.

### Indentation

[](#indentation)

As it's meant to be, SlimPHP supports an *arbitrary length* indent. Just keep the indent tree consistent throughout the slim template file.

### Tags

[](#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:

```

```

SlimPHP 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 `` &amp; it's the same as `input( type="text" )`, but shorter. Another examples:

```
input:submit( value="Send" )

```

will become ``.

It also supports new HTML5 tags such as (`input:email` =&gt; ``).

### Tag Text

[](#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 Slim go

```

renders `foo bar baz rawr.....`

Actually want `` for some reason? Use `#{}` instead:

```
p #{$something}

```

now we have ``

What if you want to output `#{}` just as it is? You can escape the '#' character in this case:

```
p \#{$notSoSpecial}

```

then we have `#{$notSoSpecial}`

### Verbatim Text

[](#verbatim-text)

The pipe tells SlimPHP to just copy the line. It essentially escapes any processing. Each following line that is indented greater than the pipe is copied over.

```
body
  p
    | This line is on the left margin.
       This line will have one space in front of it.
         This line will have two spaces in front of it.
           And so on...

```

### Inline html &lt;

[](#inline-html-)

You can write html tags directly in SlimPHP which allows you to write your templates in a more html like style with closing tags or mix html and Slim style. The leading &lt; works like an implicit |:

```

  head
    title Example

    - if ($articles):
    - else:
      table
        - foreach ($articles as $a):
          #{$a->name}#{$a->description}

```

### Nesting

[](#nesting)

```
ul
  li one
  li two
  li three

```

### Attributes

[](#attributes)

SlimPHP currently supports '(' and ')' as attribute indicator and colon(,) or space as delimitor.

```
a (href='/login', title='View login page' data-id="13") Login

```

We need to escape opening parenthesis if it comes to the very beginning character of text node, otherwise no need to escape:

```
a (href='/login', title='View login page') \(Login)
a (href='/login', title='View login page') Login (with Twitter)

```

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)

```

Another possibly awesome feature goes here:

```
input:checkbox (#{$user->isAdmin() ? 'checked' : ''} name=is_admin)

```

Will render just as follows:

```
 name="is_admin" type="checkbox" />

```

Note: Leading / trailing whitespace is *ignored* for attr pairs.

### Doctypes

[](#doctypes)

To add a doctype simply use `doctype` followed by an optional value:

```
doctype

```

Will output the *transitional* doctype, however:

`doctype html` (or simply `doctype 5`)

Will output HTML5's doctype. Below are the doctypes defined by default, which can easily be extended:

```
$doctypes = array(
	'xml'               => '',
	'xml ISO-8859-1'    => '',
	'html'          => '',
	'5'             => '',
	'1.1'           => '',
	'strict'        => '',
	'frameset'      => '',
	'mobile'        => '',
	'basic'         => '',
	'transitional'  => ''
);

```

Comments
--------

[](#comments)

### SlimPHP Comments

[](#slimphp-comments)

SlimPHP supports sharp comments (`/ COMMENT`). So SlimPHP block:

```
/ SLIMPHP
- $foo = "";
p
  - switch ($foo):
    - case 2:
      p.foo= $foo
	/- case 'strong':
	  - strong#name= $foo * 2
    - case 5:
      p some text

```

will be compiled into:

```

            some text

```

### HTML Comments

[](#html-comments)

SlimPHP supports HTML comments (`/! comment`). So block:

```
peanutbutterjelly
  /! This is the peanutbutterjelly element
  | I like sandwiches!

```

will become:

```

  I like sandwiches!

```

As with multiline comments:

```
/!
  p This doesn't render...
  div
    h1 Because it's commented out!

```

that compile to:

```

```

### IE Conditional Comments

[](#ie-conditional-comments)

Also, SlimPHP supports IE conditional comments, so:

```
/! [if IE]
  a( href = 'http://www.mozilla.com/en-US/firefox/' )
    h1 Get Firefox

```

will be parsed to:

```

```

Filters
-------

[](#filters)

Filters are prefixed with `:`, for example `:javascript` or `:cdata` and pass the following block of text to an arbitrary function for processing. View the *features*at the top of this document for available filters.

```
body
  :php
    $data = 40;
    $data /= 2;
    echo $data;

```

Renders:

```

```

Code
----

[](#code)

### Buffered / Non-buffered output

[](#buffered--non-buffered-output)

SlimPHP currently supports two classifications of executable code. The first is prefixed by `-`, and is not buffered:

```
- var $foo = 'bar';

```

This can be used for conditionals, or iteration:

```
- foreach ($items as $item):
  p= $item

```

Due to SlimPHP's buffering techniques the following is valid as well:

```
- if ($foo):
  ul
    li yay
    li foo
    li worked
- else:
  p hey! didnt work

```

Second is echoed code, which is used to echo a return value, which is prefixed by `=`:

```
- $foo = 'bar'
= $foo
h1= $foo

```

Which outputs

```

```

### Code blocks

[](#code-blocks)

Also, SlimPHP has Code Blocks, that supports basic PHP template syntax:

```
ul
  - while (true):
    li item

```

Will be rendered to:

```

    item

```

But don't forget about colons `:` after instructions start (`- if(true) :`).

There's bunch of default ones: `if`, `else`, `elseif`, `while`, `for`, `foreach`, `switch`, `case`.

Here's another convenient way to write multiline PHP code block:

```
- $user = [ \
	'username' 		=> 'clthck',
	'first_name' 	=> 'Joey',
  ];

```

This will be interpreted as:

```

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

3838d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14348482?v=4)[elquimista](/maintainers/elquimista)[@elquimista](https://github.com/elquimista)

---

Top Contributors

[![fantastic16](https://avatars.githubusercontent.com/u/22222825?v=4)](https://github.com/fantastic16 "fantastic16 (18 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clthck-slimphp/health.svg)

```
[![Health](https://phpackages.com/badges/clthck-slimphp/health.svg)](https://phpackages.com/packages/clthck-slimphp)
```

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3851.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.0k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.2k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

281.8k](/packages/webkinder-sproutset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
