PHPackages                             jakesee/slim-template-response - 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. jakesee/slim-template-response

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

jakesee/slim-template-response
==============================

A Slim Framework add-on that allows deferred parsing and rendering of template so that template data can be examined or modified.

1.0.1(8y ago)140MITPHPPHP &gt;=5.6.4

Since Nov 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/jakesee/Slim-Template-Response)[ Packagist](https://packagist.org/packages/jakesee/slim-template-response)[ RSS](/packages/jakesee-slim-template-response/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Slim-Template-Response
======================

[](#slim-template-response)

A [Slim Framework](https://github.com/slimphp/Slim) add-on that allows deferred parsing and rendering of template so that template data can be examined or modified.

Install
-------

[](#install)

```
composer require jakesee/slim-template-response ^1.0.1

```

Detailed Explanation
--------------------

[](#detailed-explanation)

Due to the way [Slim Framework](https://github.com/slimphp/Slim) is designed, the templating engines suggested by Slim Framework all write directly to the ResponseInterface stream directly in the controller, as such, there is no way to examine the template data variables or modify them after the controller exits, for example, during the outgoing middleware pathway. For this reason, this Slim-Template-Response adds a simple way to hold the template variables until the very end before finally writing the data to the stream.

Without modifying how Slim works, we can use the following to defer the writing:

```
$app->respond($app->run(true)->render());

```

instead of

```
$app->run();

```

### Middleware

[](#middleware)

As a result, you can modify the template variables in any middleware after the controller exits:

```
class MyMiddleware
{
	function __invoke($request, $response, $next)
	{
		// incoming loop
		...

		// call the next middleware
		$response = $next($request, $response);

		// controller is called eventually and returns:
		// return $response->withTemplate(...);

		// outgoing loop, modify template data
		$response->getTemplate()->data['total'] = 50;

		return $response;
	}
}

```

### Unit Testing

[](#unit-testing)

In unit testing you can now also test the results directly by examining the data variables

```
function testDisplayTotal()
{
	// setup ...

	// Run Slim App
	$response = $app($request, $response);

	// Get the template data
	$data = $response->getTemplate()->data;

	$this->assertEquals(50, $data['total']);
}

```

Usage
-----

[](#usage)

This addon consists of a Response class (which is extended from the Slim Response class) and a Template class. Simply inject the Response class into the dependency container so that Slim App will use our extended Response class.

```
$app = new \Slim\App(); // default Slim Response is initialized by this constructor
$container = $app->getContainer();

// We just replace the Response object by injecting our extended Response into the container
$container['response'] = function($container) {

	// This is how Slim sets up the default Response object in vendor/slim/slim/Slim/DefaultServicesProvide.php.
	// We simply replicate it here as closely as possible.
	$headers = new \Slim\Http\Headers(['Content-Type' => 'text/html; charset=UTF-8']);
	$template = new \Braincase\Slim\Template($container, __DIR__ . '/../resources/views/');
	$response = new \Braincase\Slim\Response($template, 200, $headers);

	return $response->withProtocolVersion($container->get('settings')['httpVersion']);
};

// create a route
$app->get('/test', function($request, $response) {
	$response->withTemplate('default.php', [
		'firstName' => 'Jake',
		'lastName' => 'See'
	]);
});

```

The Template class uses plain PHP for templating and does not have advance features like Twig or Blade, but it is possible to use your own Template class as long as your Template class implements the TemplateInterface.

### Compatibility

[](#compatibility)

This works with Slim Framework 3 at this time of writing. There is a Slim Framework 4 upcoming and I have not tested against the newer versions.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

3089d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bc6a95837aa1f46b9969f9003bc4b83ab87145ca37ed8cb2cd47b0bada2bc90?d=identicon)[jakesee](/maintainers/jakesee)

---

Top Contributors

[![jakesee](https://avatars.githubusercontent.com/u/977809?v=4)](https://github.com/jakesee "jakesee (24 commits)")

---

Tags

templateextensionaddonslim-frameworkadd-on

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jakesee-slim-template-response/health.svg)

```
[![Health](https://phpackages.com/badges/jakesee-slim-template-response/health.svg)](https://phpackages.com/packages/jakesee-slim-template-response)
```

###  Alternatives

[templavoilaplus/templavoilaplus

Building kit for custom pages and content elements with individual fields, containers and backend layouts. Supporting drag'n'drop and multiple references.

2637.6k13](/packages/templavoilaplus-templavoilaplus)

PHPackages © 2026

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