PHPackages                             nafisc/spackle - 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. nafisc/spackle

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

nafisc/spackle
==============

A templating system for PHP

v1.1(6y ago)21.7kMITPHP

Since May 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nathan-fiscaletti/spackle)[ Packagist](https://packagist.org/packages/nafisc/spackle)[ RSS](/packages/nafisc-spackle/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Spackle
=======

[](#spackle)

> A simple templating engine for PHP

[![Sponsor Me!](https://camo.githubusercontent.com/c333a55be0058d206e8aebe9bedfa79004c7f85c2102970349acb40a81323a9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539322542382d53706f6e736f722532304d65212d626c7565)](https://github.com/sponsors/nathan-fiscaletti)[![StyleCI](https://camo.githubusercontent.com/49a69fb1e2c146057b9a7a8a440da9a4e0d7bf877b90f438536c7352f2da2a43/68747470733a2f2f7374796c6563692e696f2f7265706f732f3138353435343839322f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/185454892)[![Total Downloads](https://camo.githubusercontent.com/1de7f86eb9a6c0fad689d4bf01a190d6e9ec9613b9c6d66817b9e0d075fa321a/68747470733a2f2f706f7365722e707567782e6f72672f6e61666973632f737061636b6c652f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/nafisc/spackle)[![Latest Stable Version](https://camo.githubusercontent.com/8fb1ffde8c11cedde4323334fa1f8c77ed7cb3eb457f6471b2170977de9258a8/68747470733a2f2f706f7365722e707567782e6f72672f6e61666973632f737061636b6c652f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/nafisc/spackle)[![Latest Unstable Version](https://camo.githubusercontent.com/9dae5bcf2af4210096e7c40766aef19116bc95d65a7e1ab54fe09d2a45ad4770/68747470733a2f2f706f7365722e707567782e6f72672f6e61666973632f737061636b6c652f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/nafisc/paraspacklemeterparser)[![License](https://camo.githubusercontent.com/c7ea0c6b1a4b3a3436c7540e47837e6328cf8aef9d051ef84e9a665b3f95ed50/68747470733a2f2f706f7365722e707567782e6f72672f6e61666973632f737061636b6c652f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/nafisc/spackle)

Spackle allows you to add code blocks and substitutions to any file.

Creating Templates
------------------

[](#creating-templates)

### Substitutions

[](#substitutions)

> Substitution Notation: `{{...}}`

```

   Hello, my name is {{name}}.

```

Substitutions will be replaced based on the configuration of their Parser.

### Code Blocks

[](#code-blocks)

> Code Block Notation: `{{> ...
    echo "Hello, Word!";

  foreach ({{likes}} as $likeable) {
    echo '';
    echo $likeable;
    echo '';
  }
 Plugin Notation: `{{key ...  See [CodeBlockParser.php](./src/Spackle/Plugins/CodeBlockParser.php) for an example of a plugin.

```
class MyPlugin extends \Spackle\Plugin
{
    // The key used to notate the beginning of this element.
    public $key = 'url';

    // Parse each element found matching this plugin.
    // {{url some/data addPlugin(new MyPlugin());
```

Parsing Templates
-----------------

[](#parsing-templates)

Once you've created a template, you can parse it in PHP. To parse the template you need to create an instance of `\Spackle\TemplateParser`. In the following example, we will use the `\Spackle\FileParser` class. It is a subclass of the `TemplateParser`, the only difference being that it loads the contents of a file in instead of using a string.

For this example, we will use the following Spackle Template stored in `./test.spackle`.

```
Welcome to Spackle!

Spackle was created by {{name}}.

Some things that {{name}} likes are:

{{>
    foreach ({{likes}} as $likeable) {
        echo '';
        echo $likeable;
        echo '';
    }
 echo $this->bound;
