PHPackages                             jelix/castor - 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. jelix/castor

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

jelix/castor
============

A template engine using a simple syntax

v1.2.0(3mo ago)1116.2k↓20.2%1[3 issues](https://github.com/jelix/castor/issues)1LGPL-2.1PHPPHP &gt;=7.4

Since Nov 28Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jelix/castor)[ Packagist](https://packagist.org/packages/jelix/castor)[ Docs](http://jelix.org)[ RSS](/packages/jelix-castor/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (11)Used By (1)

Castor is a template engine for PHP, using syntax similar to PHP.

Features
========

[](#features)

- A simple Api to inject data and to generate content
- A language with a syntax similar to PHP, but a bit simpler to ease learning
- Templates can be a file or a simple string
- Efficient generator: template files are "compiled" to PHP files
- A sandbox mode, to fetch untrusted templates (templates uploaded by a user in a CMS for example). This mode has less capabilities of course.
- A plugin system
- Plugins can be specific to a content type (HTML, XML, text…), so they produce right contents.
- a system of “meta”: allow the template to expose data to PHP code. For example, a "meta" can be an url of a stylesheet to use with the generated content.

Compatible with PHP 7.4 to 8.5.

Version
=======

[](#version)

The master branch is the development branch. It has sources of the next major version 2.0.0.

There are many breaking changes on the API compared to the 1.x version. It has also a new plugin system. See CHANGELOG\_V2.md for more details.

See the branch 1.x for the last stable version, used in the Jelix Framework 1.8.

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

[](#installation)

You can install it from Composer. In your project:

```
composer require "jelix/castor"

```

Usage
=====

[](#usage)

A template file `test.ctpl`:

```
{! autoescape !}
{{ $titre|upper }}

{% foreach $users as $user %}
{{$user->name}} ({{$user->birthday|datetime:'d/m/Y'}})
    {{$user->biography|raw}}

{% endforeach %}

```

The PHP code:

```
// directory where compiled templates are stored
$cachePath = realpath(__DIR__.'/temp/') . '/';

// directory where templates can be found
$templatePath = __DIR__.'/';

// create a configuration object. See its definition to learn about all of its options
$config = new \Jelix\Castor\Config($cachePath, $templatePath);

// let's create a template engine
$tpl = new \Jelix\Castor\Castor($config);

// assign some values, so they will be available for the template

$users = array(
    // User in an example class...
    new User('Tom', '2001-02-01'),
    new User('Laurent', '1990-03-01'),
    new User('Bob', '1970-05-25')
 );
$tpl->assign('users', $users);
$tpl->assign('titre', 'This is a test !');

// content is generated from the given template file and returned
$content = $tpl->fetch('test.ctpl');

// or content is generated from the given template file and sent directly to the browser
$tpl->display('test.ctpl');
```

To know more, see the docs/ directory.

History
=======

[](#history)

Castor was formerly known as jTpl and was used in the [Jelix Framework](http://jelix.org)since 2006. There was a specific version, "jTpl standalone", existing for years to use jTpl without Jelix, but it was never released as a stable version.

In 2015, jTpl was completely "extracted" from Jelix (starting to Jelix 1.7), and is now available as a standalone component under the name "Castor", with true stable releases.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance61

Regular maintenance activity

Popularity34

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 86.6% 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 ~418 days

Recently: every ~216 days

Total

10

Last Release

102d ago

PHP version history (5 changes)v1.0.0PHP &gt;=5.3

v1.1.0PHP &gt;=5.6

v1.1.2PHP &gt;=5.6 &lt;=8.2

v1.1.3PHP &gt;=5.6 &lt;8.4

v1.2.0PHP &gt;=7.4

### Community

Maintainers

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

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

---

Top Contributors

[![laurentj](https://avatars.githubusercontent.com/u/336034?v=4)](https://github.com/laurentj "laurentj (355 commits)")[![julieni](https://avatars.githubusercontent.com/u/995738?v=4)](https://github.com/julieni "julieni (14 commits)")[![kissifrot](https://avatars.githubusercontent.com/u/105998?v=4)](https://github.com/kissifrot "kissifrot (10 commits)")[![bastnic](https://avatars.githubusercontent.com/u/84887?v=4)](https://github.com/bastnic "bastnic (9 commits)")[![doubleface](https://avatars.githubusercontent.com/u/228695?v=4)](https://github.com/doubleface "doubleface (5 commits)")[![bricet](https://avatars.githubusercontent.com/u/968476?v=4)](https://github.com/bricet "bricet (4 commits)")[![kewix](https://avatars.githubusercontent.com/u/1006956?v=4)](https://github.com/kewix "kewix (4 commits)")[![ziwot](https://avatars.githubusercontent.com/u/13657413?v=4)](https://github.com/ziwot "ziwot (2 commits)")[![dsdenes](https://avatars.githubusercontent.com/u/123850?v=4)](https://github.com/dsdenes "dsdenes (2 commits)")[![Tpt](https://avatars.githubusercontent.com/u/458123?v=4)](https://github.com/Tpt "Tpt (2 commits)")[![khena](https://avatars.githubusercontent.com/u/2631622?v=4)](https://github.com/khena "khena (1 commits)")[![vincentv](https://avatars.githubusercontent.com/u/304983?v=4)](https://github.com/vincentv "vincentv (1 commits)")[![njeudy](https://avatars.githubusercontent.com/u/995787?v=4)](https://github.com/njeudy "njeudy (1 commits)")

---

Tags

template

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jelix-castor/health.svg)

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

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.6k39.0M235](/packages/phpoffice-phpword)[rize/uri-template

PHP URI Template (RFC 6570) supports both expansion &amp; extraction

435149.5M63](/packages/rize-uri-template)[mopa/bootstrap-sandbox-bundle

Seperate live docs from code

256.8k](/packages/mopa-bootstrap-sandbox-bundle)[larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

143.7k](/packages/larablocks-pigeon)

PHPackages © 2026

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