PHPackages                             ganti/php-template-blocks - 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. ganti/php-template-blocks

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

ganti/php-template-blocks
=========================

Simple Templateengine, e.g. to compile eMails

120PHPCI failing

Since Oct 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ganti/php-template-blocks)[ Packagist](https://packagist.org/packages/ganti/php-template-blocks)[ RSS](/packages/ganti-php-template-blocks/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

phpTemplateBlocks
=================

[](#phptemplateblocks)

Simple Template Class, e.g. for eMail Template

Features
--------

[](#features)

- Substitution/replacement of variables
- Showing/Hiding content blocks with conditions OR, AND
- Output Text as HTML or Text, with one templatefile.

Usage
-----

[](#usage)

### Install

[](#install)

`composer require ganti/php-template-blocks`

### Example`

[](#example)

```
 Hallo {{name}}

{{block:block1}}
  This is block1, shown in HTML and text
{{endblock:block1}}

{{block:block1_html}}
  This is block1, shown only in HTML
{{endblock:block1_html}}

{{block:block1_text}}
  This is block1_text, shown only in text
{{endblock:block1_text}}

{{block:and,block1,block2,block3}}
  This is Block1,2and3, shown only if block1, block2 and block3 are true
{{endblock:and,block1,block2,block3}}

{{block:and,block2_text,block3}}
  This is Block2or3_text, shown only in text if block2 and block3 are true
{{endblock:or,block2_text,block3}}
```

```
    $file = __DIR__.'/example.html';
    $vars = array(  'name' => 'Hal',
                    'var2' => 'Foo',
                    'var3' => 'Foobar'
    );
    $blocks = array('block1' => True,
                    'block2' => False,
                    'block3' => True
    );

    $t = new phpTemplateBlocks($file = $file, $vars = $vars, $blocks = $blocks);
    $output =  $t->getOutput();
    echo $output;
```

### Output as HTML or text

[](#output-as-html-or-text)

```
$t->getOutput();        //Output as HTML
$t->getOutput('html');  //Output as HTML
$t->getOutputHTML();    //Output as HTML

$t->getOutput('text');  //Output as text
$t->getOutputText();    //Output as text
```

### add vars and blocks after creating an instance

[](#add-vars-and-blocks-after-creating-an-instance)

```
$mt = new phpTemplateBlocks($file = $file);
$mt->vars['var1'] = 'var1xxx';
$mt->blocks['block1'] = True;
```

### Variable replacement

[](#variable-replacement)

Template: `This is a {{animal}}.`

```
$t = new phpTemplateBlocks($file = $file);
$t->vars['animal'] = 'dog';
```

Output:

```
This is a dog.
```

Show / Hide Blocks
------------------

[](#show--hide-blocks)

Template:

```
{{block:block1}}
    This is block1
{{endblock:block1}}
```

```
$t = new phpTemplateBlocks($file = $file);
$t->blocks['block1'] = True;
```

Output:

```
    This is block1
```

Combined Blocks
---------------

[](#combined-blocks)

Combined blocks allow to show a block if one of the keys are `true`

Template:

```
{{block:block2,block3}}
    This is Block2or3
{{endblock:block2,block3}}
```

```
$mt = new mailTemplate($file = $file);
$mt->blocks['block2'] = False;
$mt->blocks['block3'] = True;
```

Output:

```
    This is Block2or3
```

### Condition OR (default)

[](#condition-or-default)

```
{{block:or,block2,block3}}
  This is Block2or3, shown only in text if block2 or block3 are true
{{endblock:or,block2,block3}}
```

### Condition AND

[](#condition-and)

```
{{block:and,block2_text,block3}}
  This is Block2and3_text, shown only in text if block2 and block3 are true
{{endblock:and,block2_text,block3}}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/944a6adcd9f8a2c521d242472278a4bc81de512bc2e0abac3c17bba8f3d4725c?d=identicon)[ganti](/maintainers/ganti)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/ganti-php-template-blocks/health.svg)

```
[![Health](https://phpackages.com/badges/ganti-php-template-blocks/health.svg)](https://phpackages.com/packages/ganti-php-template-blocks)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

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

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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