PHPackages                             maplephp/swiftrender - 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. maplephp/swiftrender

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

maplephp/swiftrender
====================

PHP SwiftRender is a pure and highly portable PHP template library.

v2.0.1(1y ago)2422[1 PRs](https://github.com/MaplePHP/SwiftRender/pulls)3Apache-2.0PHPPHP &gt;=8.0

Since Nov 29Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/SwiftRender)[ Packagist](https://packagist.org/packages/maplephp/swiftrender)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-swiftrender/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (3)

SwiftRender
===========

[](#swiftrender)

PHP SwiftRender is a pure PHP advanced template library. It offers several advantages for developers who need to create and render templates in PHP applications. Firstly, it can improve performance, as there is no need for an additional language or engine to process the template. This can result in faster rendering times and reduced overhead. Additionally, a pure PHP template library is highly portable, as it can be used in almost any PHP application, regardless of the underlying platform or framework.

PHP SwiftRender offers greater flexibility and control over the rendering process. Developers that knows PHP can structure and design their templates in ways that better suit their specific needs, resulting in more efficient and effective templates.

PHP is a widely-used language, most developers are already familiar with its syntax and conventions. This makes it easier to learn and use a pure PHP template library than an entirely new templating language or engine.

Usage
-----

[](#usage)

### Initialisation

[](#initialisation)

One time setup to use through the application.

```
use MaplePHP\Output\SwiftRender;
use MaplePHP\DTO\Format;

$swift = new SwiftRender();

$swift->setIndexDir(dirname(__FILE__)."/resources/") // Set index directory
->setViewDir(dirname(__FILE__)."/resources/views/")  // Set view directory
->setPartialDir(dirname(__FILE__)."/resources/partials/"); // Set partials directory

// Prepare/bind "/resources/index.php"
$swift->setIndex("index");

// Prepare/bind "/resources/views/main.php"
$swift->setView("main");

// Prepare/bind "/resources/partials/article.php"
$swift->setPartial("article", [
	"date" => "2023-02-30 15:33:22",
    "name" => "This is an article",
    "content" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
    "feed" => [
        [
            "headline" => "test 1",
            "description" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt, architecto."
        ],
        [
            "headline" => "test 2",
            "description" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt, architecto."
        ]
    ]
]);
// Keep in mind that the data usually comes from the database and that it should/might be called from you controller.
// E.g. $swift->setPartial("article", $mysqli->fetch_objects());
```

### Templating

[](#templating)

#### Index

[](#index)

The file **/resources/index.php** has already been bounded under the initialisation section above **$swift-&gt;setIndex("index")**. The file looks like this:

```
>

	execute(); ?>

	partial("navigation")->get(); ?>

		view()->get(); ?>

```

#### View

[](#view)

The file **/resources/views/main.php** has already been bounded under the initialisation section above **$swift-&gt;setView("main")**. The file looks like this:

```

	partial("article")->get(); ?>

```

#### Partial

[](#partial)

The file **/resources/partials/article.php** has already been bounded under the initialisation section above **$swift-&gt;setPartial("article", ...)**. The file looks like this:

```

		clockFormat("Y/m/d"); ?>
		stExcerpt(20); ?>

	count() > 0): ?>

		fetch() as $row): ?>

			headline->strUcFirst(); ?>
			description; ?>

```

#### Partial functionality

[](#partial-functionality)

The partials all arguments will automatically be converted to an object with a lot of extended functionality. Here is some:

```
echo $date; // 2023-02-30 15:33:22
echo $date->clockFormat("Y/m/d"); // 2023/02/30
// Will strip all html tags, replace regular line breaks with "" and uppercase the first letter
echo $content->strStripTags()->strNl2br()->strUcfirst();

// Loop through an array
if($feed->count() > 0) foreach($feed->fetch() as $row) {
	echo $row->headline->strUcFirst() . "";
}
```

#### Run the template engine

[](#run-the-template-engine)

You can run the template engine later in an empty file, emitter or router dispatcher. It all depends on your setup.

```
echo $swift->index()->get();
```

#### Dynamic views

[](#dynamic-views)

You can also create a dynamic view that will overwrite the current view if called. This is great for e.g. showing a 404 page.

In this example the current view which is **/resources/views/main** will be replaced with the view **/resources/views/httpStatus.php** when response status code is (403, 404 e.g.).

```
// MaplePHP framework (PSR response). Just using this in this example to handle status response codes
use MaplePHP\Http\Response;

$swift->bindToBody(
    "httpStatus",
    Format\Arr::value(Response::PHRASE)->unset(200, 201, 202)->arrayKeys()->get()
    // This method will load all HTTP Request status codes (like 403, 404 e.g.) except for (200, 201, 202)
);

$swift->findBind($response->getStatusCode());
```

#### Easy DOM manipulation

[](#easy-dom-manipulation)

Advance DOM creation and works great with stuff like the Metadata because you can later in change values and attributes in the controller.

```
// Advance DOM creation and works great with stuff like the Metadata
$dom = MaplePHP\Output\Dom\Document::dom("head");
$dom->bindTag("title", "title")->setValue("Meta title");
$dom->bindTag("meta", "description")->attr("name", "Description")->attr("content", "Lorem ipsum dolor sit amet.");

// Then later in controller you can change the meta title and description
$head = MaplePHP\Output\Dom\Document::dom("head");
$head->getElement("title")->setValue("New meta title");
$head->getElement("description")->attr("content", "New meta description...");
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance57

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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 ~68 days

Recently: every ~112 days

Total

8

Last Release

416d ago

Major Versions

v1.2.2 → v2.0.02024-10-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (8 commits)")[![danielRConsid](https://avatars.githubusercontent.com/u/169045496?v=4)](https://github.com/danielRConsid "danielRConsid (1 commits)")

---

Tags

componentstemplateviewsenginepartialsoutput buffer

### Embed Badge

![Health badge](/badges/maplephp-swiftrender/health.svg)

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

###  Alternatives

[latte/latte

☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites. Introduces context-sensitive escaping.

1.3k15.7M683](/packages/latte-latte)[duncan3dc/blade

Use Laravel Blade templates without the full Laravel framework

160499.5k24](/packages/duncan3dc-blade)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

24085.2k](/packages/anourvalar-office)[phug/phug

Pug (ex-Jade) facade engine for PHP, HTML template engine structured by indentation

67292.2k13](/packages/phug-phug)[sitegeist/fluid-components

Encapsulated frontend components with Fluid's ViewHelper syntax

55339.1k3](/packages/sitegeist-fluid-components)[sitegeist/fluid-styleguide

Living styleguide for Fluid Components

16227.4k1](/packages/sitegeist-fluid-styleguide)

PHPackages © 2026

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