PHPackages                             cinam/template-parser - 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. cinam/template-parser

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

cinam/template-parser
=====================

Template parser

1.1.4(5y ago)067MITPHPPHP &gt;=5.4.0CI failing

Since Dec 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/cinam/template-parser)[ Packagist](https://packagist.org/packages/cinam/template-parser)[ Docs](http://github.com/cinam/template-parser)[ RSS](/packages/cinam-template-parser/feed)WikiDiscussions master Synced 3d ago

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

Template parser
===============

[](#template-parser)

A simple text parser. It allows you to perform following text transformations:

- replace placeholders with scalar variables,
- replace placeholders from array variables using iteration,
- process logical conditions.

There is no limit for nesting arrays.

Usage
-----

[](#usage)

```
$parser = new \Cinam\TemplateParser\Parser();
$result = $parser->parse($text, $variables);
```

Examples
--------

[](#examples)

### Example 1 - Simple variable

[](#example-1---simple-variable)

```
$text = 'Hello, {user}!';
$variables = [
    'user' => 'Peter',
];

$parser = new \Cinam\TemplateParser\Parser();
echo $parser->parse($text, $variables);
```

*Hello, Peter!*

### Example 2 - Condition

[](#example-2---condition)

```
$text = parse($text, ['age' => 18]);
```

*You are an adult*

```
echo $parser->parse($text, ['age' => 15]);
```

*Sorry, you are too young*

### Example 4 - Iteration

[](#example-4---iteration)

```
$text =
