PHPackages                             ldf/gutenberg - 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. ldf/gutenberg

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

ldf/gutenberg
=============

PHP based templa

v0.2.2(6y ago)1199MITPHPPHP &gt;=7.1CI failing

Since May 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gotardo/ldf-gutenberg)[ Packagist](https://packagist.org/packages/ldf/gutenberg)[ RSS](/packages/ldf-gutenberg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (13)Used By (0)

ldf-gutenberg v0.2.2
====================

[](#ldf-gutenberg-v022)

[![Build Status](https://camo.githubusercontent.com/ecbbd44b81fe4fceb8d187ecbc0f7585730de0f1febd7c239df7b53a1b1c48e4/68747470733a2f2f7472617669732d63692e6f72672f676f746172646f2f6c64662d677574656e626572672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gotardo/ldf-gutenberg)[![Maintainability](https://camo.githubusercontent.com/1d6e55ec75893155d2303a93624ec472be2e71a59194604b3e6aa9b33567c8b1/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31313862326437373939653931663365366365302f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/gotardo/ldf-gutenberg/maintainability)[![Test Coverage](https://camo.githubusercontent.com/188c022ca428fdb926a6f86bc527ddd248dff513c65e3b55f83ae4debbe5d7ec/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31313862326437373939653931663365366365302f746573745f636f766572616765)](https://codeclimate.com/github/gotardo/ldf-gutenberg/test_coverage)

Gutenberg is a view renderer written in PHP and based on the fact that view **must** be totally separated from logic.

This system will allow you to easily substitute some variables for values and compose views in an easy way for a CMS, but you will not find control structures such as if/ese statements or even template inheritance. If you are looking for this kind of feature, I recommend to have a look at [Blade](https://laravel.com/docs/5.6/blade)or [Twig](https://twig.symfony.com/).

How to install
--------------

[](#how-to-install)

You can install Gutenberg with [composer](https://getcomposer.org/):

```
composer require ldf/gutenberg
```

Instantiate Gutenberg
---------------------

[](#instantiate-gutenberg)

Gutenberg is instantiated by a builder class called `Gutenberg`:

```
$Gutenberg = Gutenberg::ForWorkspace('./path/to/templates');
```

By using the fluent api, you will be able to set up some extra behaviours. The following lines will build a Gutenberg object with Wipe Out mode enabled:

```
// Get the object
$Gutenberg = Gutenberg::ForWorkspace('./path/to/templates')
    ->withWipeOut();

// Call the render function to get the rendered page
return $Gutenberg->render('page', [
    'var1' => 'value1',
    'var2' => 'value2',
]);
```

Template files
--------------

[](#template-files)

Template files are just .html files (as they are expected to contain just html with a couple of Guttemberg tweaks). They must be place in a workspace.

A workspace is essentially a path to a directory.

Templates are referenced by an id which, by convention, resolves to a file in the workspace.

For example, a template identified by `myTemplate` will resolve to path `./workspace/myTemplate.html` and another tempalte identified by `partials/_widget` will resolve to path `./workspace/partials/_widget.html`

- By the way, it is recommended that, by convention you prefix your partial files with underscore `_`(you may recognize this convention).

If you decide to an extension other than `.html` for your templates, you can specify this as part of your identifier with something like `myTemplate.tpl`.

Keywords
--------

[](#keywords)

Gutenberg provides some expressions to allow you to define some dinamic points in your templates.

### Generally speaking

[](#generally-speaking)

Expressions in Gutenberg are anything you place between double curly braces.

If you want to print double curly braces you must use the html entity instead:

```
The value of variable "myvar" is {{ myvar }}
&#123;&#123;This will be displayed in the html.&#124;;&#124;
```

### Variables

[](#variables)

Variables will be refered as {{ varname }}

### import

[](#import)

`{{ import _partialTemplateId }}`

Please, notice that in this case the Id begins with an underscore `_`. This way Gutenberg knows that this template is a partial template. Partial templates, by convention must begin by underscore. Indeed, if they don't begin by underscore they import expression will be ignored.

Also notice that you are already in a workspace, so you can not import templates from another workspace. This way you are forced to avoid cross dependencies.

### wrapper

[](#wrapper)

`{{ wrapper tplname}}`

We don't support inheritance -no, we don't like inheritance. Instead, you are able to wrap templates. Think of wrapping as a sort of reverse-import in which the wrapped template can define one -and only one- template to be wrapped.

When you use wrapping, the source code file must start exactly by the wrapper command.

Wrappers use the `{{ content }}` mark to define the place were the inner template will be wrapped.

### comments

[](#comments)

`{{-` (a.k.a X-Wing operator)

The rest of the line is a comment and will be ingored. For multiple-line comments you can send some X-Wing spaceships:

```
{{-
{{- This is a multi-line comment.
{{- You can use it as header of template files.
{{- Everything you write in a comment will be ignored and will not appear in the ouput.
{{-

    This will be rendered

```

Now, be a good kid and go add some comments to your code.

### Control structures

[](#control-structures)

So, how can I add some structures such as `if`/`else` or `foreach`? The answer is easy: **you can't**.

Logic should not be on your templates, so you must take care of passing exactly some ready-to-use substitution values.

Extra options
-------------

[](#extra-options)

By using the builder, you will be able to configure some extra options

### WipeOut

[](#wipeout)

You can enable wipe out feature by calling `withWipeOut`.

When Wipe out option is enabled any Gutenberg tag which is not recognized, e.g. {{ unknownVariable }}, will be cleaned from the template. An E\_USER\_WARNING level error will be raised.

```
$Gutenberg = Gutenberg::ForWorkspace('./path/to/templates')
    ->withWipeOut()
    ->get();
```

Extending Gutenberg's functionality.
------------------------------------

[](#extending-gutenbergs-functionality)

Gutenberg provides a feature to add some custom compilers. This will allow you to create your own language expressions. You can add your own language expression calls by implementing ICompiler:

```
class MyCustomCompiler implements \Ldf\Gutenberg\ICompiler
{
    public function compile(string $tpl) : string
    {
        ...
    }
}
```

You can add as many custom compilers as you want.

```
Gutenberg::ForWorkspace('./FakeTemplates')
    ->addCustomCompiler($myCustomCompiler1)
    ->addCustomCompiler($myCustomCompiler2)
```

Just take into account that compilers are executed sequentially, begining by the core compilers and the core options. Custom compilers will be executed at the end.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Recently: every ~116 days

Total

9

Last Release

2415d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22c57f8c71b5e3f252d3a7d47832e49ef04136378a136963e7ebcb947830ab4c?d=identicon)[gotardo](/maintainers/gotardo)

---

Top Contributors

[![gotardo](https://avatars.githubusercontent.com/u/1632996?v=4)](https://github.com/gotardo "gotardo (43 commits)")

---

Tags

templating

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ldf-gutenberg/health.svg)

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

###  Alternatives

[twig/twig

Twig, the flexible, fast, and secure template language for PHP

8.4k443.2M5.8k](/packages/twig-twig)[mustache/mustache

A Mustache implementation in PHP.

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

Smarty - the compiling PHP template engine

2.3k39.1M393](/packages/smarty-smarty)[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M108](/packages/timber-timber)[league/plates

Plates, the native PHP template system that's fast, easy to use and easy to extend.

1.5k5.9M230](/packages/league-plates)[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)

PHPackages © 2026

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