PHPackages                             hxgf/slime-render - 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. hxgf/slime-render

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

hxgf/slime-render
=================

PHP abstraction functions to help more easily render views for Slim Framework with Handlebars (LightnCandy).

1.4.1(11mo ago)157[8 issues](https://github.com/jyoungblood/slime-render/issues)2MITPHP

Since May 6Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/jyoungblood/slime-render)[ Packagist](https://packagist.org/packages/hxgf/slime-render)[ Docs](https://github.com/jyoungblood/slime-render)[ RSS](/packages/hxgf-slime-render/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (12)Used By (2)

SLIME Render
============

[](#slime-render)

### PHP abstraction functions to help more easily render views for [Slim Framework](https://www.slimframework.com/) (v4) with plain text, HTML, JSON, and Handlebars (using [LightnCandy](https://github.com/zordius/lightncandy))

[](#php-abstraction-functions-to-help-more-easily-render-views-for-slim-framework-v4-with-plain-text-html-json-and-handlebars-using-lightncandy)

These functions aim to provide a simplified and standardized interface for rendering various types of data-driven responses as PSR-7 objects for use with Slim.

Included with the [Slime boilerplate](https://github.com/jyoungblood/slime) for Slim applications.

Installation
============

[](#installation)

Easy install with composer:

```
composer require jyoungblood/slime-render

```

```
use Slime\render;
require __DIR__ . '/vendor/autoload.php';
```

Requirements
------------

[](#requirements)

- [Slim Framework](https://www.slimframework.com/) 4
- [LightnCandy](https://github.com/zordius/lightncandy) &gt;= 1.2.6
- PHP &gt;= 7.4

Usage
=====

[](#usage)

render::html($request, $response, $string, $status = 200)
---------------------------------------------------------

[](#renderhtmlrequest-response-string-status--200)

Renders a string as HTML. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).

```
$app->get('/', function ($req, $res, $args) {

  return render::html($req, $res, 'Hey whats up');

});
```

Additionally, a path to an HTML file can be specified to load and render instead of a string:

```
$app->get('/', function ($req, $res, $args) {

  return render::html($req, $res, '/hey/whats-up.html');

});
```

render::text($request, $response, $string, $status = 200)
---------------------------------------------------------

[](#rendertextrequest-response-string-status--200)

Renders a string as plain text. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).

```
$app->get('/', function ($req, $res, $args) {

  return render::text($req, $res, 'Hey whats up');

});
```

render::hbs($request, $response, $parameters, $status = 200)
------------------------------------------------------------

[](#renderhbsrequest-response-parameters-status--200)

Renders a specific Handlebars template with an array of data, including any partials and global `locals` variables array. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).

```
$app->get('/', function ($req, $res, $args) {

  return render::hbs($req, $res, [
    'template' => 'index',
    'layout' => '_layouts/base', // optional "wrapper" layout template
    'title' => 'Page title', // for HTML  tag
    'data' => [
      'name' => 'Ringo',
      'friends' => [
        'Paul', 'George', 'John'
      ]
    ],
  ], 200); // optional status code, 200 by default

});
```

The parser function expects templates to be in a `templates` directory with `html` file extension. This can be customized by defining these variables in a global `settings` array:

```
$GLOBALS['settings']['templates']['path'] = 'pages';
$GLOBALS['settings']['templates']['extension'] = 'hbs';
```

Additionally, an array of `locals` can be added to make variables available across all templates:

```
$GLOBALS['locals'] = [
  'year' => date('Y'),
  'site_title' => 'Web Site Title',
  'site_code' => 'WST',
  'site_domain' => 'example.com',
];
```

```
Welcome to {{locals.site_title}}, the year is {{locals.year}}!
```

Parameters from PHP $\_GET and $\_POST variables are automatically made available to templates rendered with this function, using the variables `{{GET}}` and `{{POST}}`:

```

Hey there, {{GET.name}}, what's it like in {{GET.location}}?
```

Check out the [Handlebars Cookbook](https://zordius.github.io/HandlebarsCookbook/) to see everything you can do with LightnCandy and Handlebars.

Additionally, we've included a few helper functions.

The `date` helper applies the PHP `date()` function to a given variable or string (or `now` keyword for the current time)

```
Date from unix timestamp: {{date unix_ts_var "d/m/Y"}}
Current date: {{date "now" "d/m/Y"}}
Date from non-unix timestamp: {{date non_unix_ts_var "d/m/Y" "convert"}}
```

The `#is` block helper allows for basic conditional logic:

```
Is it 1981? {{#is locals.year "==" "1981"}} Yes! {{else}} No! {{/is}}
```

The `concat` helper concatenates any number of strings and HBS variable data

```
{{concat "/blog/edit/" data._id}}

```

Custom helpers are easy to create. Take a look at how these helpers are defined in [initialize\_handlebars\_helpers()](https://github.com/jyoungblood/slime-render/blob/74e6e4a89a90a2490196a4d50d7466855820dd3a/src/render.php#L46). The Handlebars cookbook also has a reference for creating [custom helpers](https://zordius.github.io/HandlebarsCookbook/0021-customhelper.html) and [custom block helpers](https://zordius.github.io/HandlebarsCookbook/0022-blockhelper.html).

render::handlebars($parameters)
-------------------------------

[](#renderhandlebarsparameters)

Renders a specicific Handlebars template with data array the same as `render::hbs()`, but returns raw html instead of a PSR-7 response.

```
$app->get('/', function ($req, $res, $args) {

  echo render::handlebars([
    'template' => 'email/test',
    'data' => [
      'link' => 'https://jy.hxgf.io',
    ]
  ]);

  return $res;
});
```

render::redirect($request, $response, $string, $status = 302)
-------------------------------------------------------------

[](#renderredirectrequest-response-string-status--302)

Renders a redirect as standard Slim (PSR-7) response object with optional HTTP status code.

```
  return render::redirect($req, $res, 'https://google.com/');
```

render::json($request, $response, $data, $status = 200)
-------------------------------------------------------

[](#renderjsonrequest-response-data-status--200)

Renders an array or data as standard Slim (PSR-7) response object with `application/json` content type and optional HTTP status code.

```
$app->get('/json/', function ($req, $res, $args) {

  $data = [
    'name' => 'Ringo',
    'friends' => [
      'Paul', 'George', 'John'
    ]
  ];

  return render::json($req, $res, $data);

});
```

render::lightncandy\_html($parameters)($data)
---------------------------------------------

[](#renderlightncandy_htmlparametersdata)

Prepares and compiles a specific Handlebars template with an array of data, including any partials and global `locals` variables array.
This is automatically called by `render::hbs()` but can be used as a standalone function if desired.

```
$args = [
  'template' => 'index',
  'layout' => '_layouts/base',
  'title' => 'Page title',
];

$data = [
  'name' => 'Ringo',
  'friends' => [
    'Paul', 'George', 'John'
  ]
];

echo render::lightncandy_html($args)($data);
```

render::initialize\_handlebars\_helpers()
-----------------------------------------

[](#renderinitialize_handlebars_helpers)

For internal use by `lightncandy_html()`. Defines a couple custom Handlebars helper functions to be used by the LightnCandy compiler.

Components
==========

[](#components)

We've also created a `component` helper, which allows you to define components that accept props and handle asset management. Components are stored in the `templates/_components` directory and can include both a template file (`[name].html`) and an optional assets file (`[name].assets.html`).

Here are some examples of how to use components:

Simple Component
----------------

[](#simple-component)

In the primary template:

```
{{{component "input"
  label="Username"
  type="text"
  width="w-80"
  padding="pa3"
  name="username"
  value="j_lennon"
}}}
```

In `templates/_components/input.html`:

```

  {{label}}

```

In `templates/_components/input.assets.html`:

```

```

Using simple component with HBS variables using the `concat` helper:

```
{{{component "form/button-save"
  type="article"
  url="/blog/save"
  redirect=(concat "/blog/edit/" data._id)
  label=" Save & Reload"}}}

```

Slot Component
--------------

[](#slot-component)

In the primary template:

```
{{component "card" title="My Card Title"}}
  This is the slot content that will appear inside the card.
  You can put any HTML content here.
{{/component}}
```

In `templates/_components/card.html`:

```

  {{title}}

    {{slot}}

```

Slot components can use HBS variables as one might expect:

```
{{#component "list-table" id="list-articles" articles=articles table_columns=table_columns}}
    {{#each articles}}

          {{#if title}}{{title}}{{else}}[untitled]{{/if}}

          {{screenname}}

          {{#if published}}{{date date_published "m/d/Y"}}{{/if}}

           Edit

    {{/each}}
{{/component}}

```

Components can also be nested within slot components:

```
{{component "card" title="User Profile"}}
  {{{component "input"
    label="Full Name"
    type="text"
    width="w-100"
    name="fullname"
    value=user.fullname
  }}}

  {{{component "input"
    label="Email"
    type="email"
    width="w-100"
    name="email"
    value=user.email
  }}}
{{/component}}
```

Key features of the component helper:

- Use triple curly braces `{{{component}}}` to ensure HTML is not escaped
- The first argument is the component name (e.g., "card" or "input")
- All other attributes are passed as hash parameters
- For components that support slots (like the card), content between the opening and closing tags will be placed where `{{slot}}` appears in the template
- Assets (like CSS and JS) are automatically loaded if they exist in the component's assets file
- The component helper caches templates and assets for better performance

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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 ~112 days

Recently: every ~194 days

Total

11

Last Release

342d ago

Major Versions

0.1.0 → 1.0.02022-05-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4130bfc70d308f890899a0c223f9888271f0fd3f91879b09558ba696862d8d4?d=identicon)[jyoungblood](/maintainers/jyoungblood)

---

Top Contributors

[![jyoungblood](https://avatars.githubusercontent.com/u/56104?v=4)](https://github.com/jyoungblood "jyoungblood (29 commits)")

---

Tags

slimmustacheutilitieshandlebarslightncandyview helpersrender abstractions

### Embed Badge

![Health badge](/badges/hxgf-slime-render/health.svg)

```
[![Health](https://phpackages.com/badges/hxgf-slime-render/health.svg)](https://phpackages.com/packages/hxgf-slime-render)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[zordius/lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ).

60910.5M45](/packages/zordius-lightncandy)[proai/laravel-handlebars

A Laravel wrapper for LightnCandy for using the Handlebars (and Mustache) template engine.

38204.7k](/packages/proai-laravel-handlebars)[salesforce/handlebars-php

Handlebars processor for php

80713.2k11](/packages/salesforce-handlebars-php)[entomb/slim-json-api

Slim extension to implement fast JSON API's

268156.4k4](/packages/entomb-slim-json-api)[voodoophp/handlebars

Handlebars processor for php

34158.9k2](/packages/voodoophp-handlebars)

PHPackages © 2026

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