PHPackages                             oscarpalmer/yogurt - 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. [Framework](/categories/framework)
4. /
5. oscarpalmer/yogurt

AbandonedArchivedLibrary[Framework](/categories/framework)

oscarpalmer/yogurt
==================

A tiny templating engine.

v1.3.0(11y ago)350MITPHPPHP &gt;=5.3.0

Since Feb 28Pushed 9y ago1 watchersCompare

[ Source](https://github.com/oscarpalmer/yogurt)[ Packagist](https://packagist.org/packages/oscarpalmer/yogurt)[ Docs](http://git.io/yogurt)[ RSS](/packages/oscarpalmer-yogurt/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Yogurt
======

[](#yogurt)

[![PHP version](https://camo.githubusercontent.com/fc4edf6b1aa1c34ffad5602ffd5d0b4de8fd13e7de6d323b8d18ae41ba30b693/68747470733a2f2f62616467652e667572792e696f2f70682f6f7363617270616c6d6572253246796f677572742e706e67)](http://badge.fury.io/ph/oscarpalmer%2Fyogurt) [![Build Status](https://camo.githubusercontent.com/8eba9ebf15712fc2f4b39ba7c83d564b2cd5c84d4c1f2ae7d715099a78abe9f2/68747470733a2f2f7472617669732d63692e6f72672f6f7363617270616c6d65722f796f677572742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/oscarpalmer/yogurt) [![Coverage Status](https://camo.githubusercontent.com/22df46d3ccb0a1f0007be3d3fd1247c822f213c5340b59e1dec38d1075bef45a/68747470733a2f2f636f6465636f762e696f2f67682f6f7363617270616c6d65722f796f677572742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/oscarpalmer/yogurt)

Yogurt is a template language for PHP (`>=5.3`) inspired by [Beach's](http://beach.io) [Hammer](http://hammerformac.com). Hammer's syntax was based on regular ol' HTML comment tags, so you won't have to install another syntax highlighter for your editor. Nice, huh?

Getting started
---------------

[](#getting-started)

### Installation

[](#installation)

Yogurt is available via Composer.

```
{
  "require": {
    "oscarpalmer/yogurt": "1.*"
  }
}
```

### Basic usage

[](#basic-usage)

```
use oscarpalmer\Yogurt\Yogurt;

$yogurt = new Yogurt("./directory/for/templates", "template-extension");

$flavour = $yogurt->flavour("my-template");
# Or $flavour = new Flavour($yogurt, "my-template");

$flavour->data(array(
  "title" => "My Title"
));

$flavour->tagline = "My tagline.";

echo $flavour->taste();
# Or just echo $flavour;
```

Syntax
------

[](#syntax)

The syntax is based on regular HTML comments and the control structures (`if` and `foreach`) are based on [Twig's](//github.com/fabpot/Twig) syntax, so it shouldn't be too difficult to learn.

### Variables

[](#variables)

```

```

`variable` is a direct child of the data object (`$flavour->data();`), and the `chaining.variables.works.too` is a nested child of multiple arrays or objects inside the data object.

Variables *should* be of the `scalar` type, i.e. `boolean`, `float`, `integer`, or `string`. If not, PHP will scream.

### Variable modifiers

[](#variable-modifiers)

```

```

Variables can be modified, too.

- `dump`: dumps the variable with `var_dump`.
- `escape`: escapes bad characters, e.g. tags.
- `json`: transforms anything into valid JSON markup.
- `lowercase`: converts the string to a lowercase version of it.
- `trim`: trims the string of leading and trailing whitespace.
- `uppercase`: converts the string to an uppercase version of it.

### Including other files

[](#including-other-files)

```

```

Yogurt will then attempt to find the file in the directory supplied to Yogurt as shown in the ["Getting started" example](#getting-started); the second one will automatically append the supplied file extension.

### Looping

[](#looping)

```

```

`items` *should* be an array or object, but `item` can be whatever; just remember to chain names to access the item's children if it isn't `scalar`, like this: `item.title`.

#### Indexes

[](#indexes)

When looping, sometimes you need to know the index of the item – i.e. its place in the array or object. The item's index can be accessed by appending `_index` to the array or object's name, e.g. `array_index` for an array named `array`.

### Ifs and else-ifs

[](#ifs-and-else-ifs)

```

Title exists.

Page is "some-page".

Number is "1234".

This is pretty cool.

```

Supported comparison operators are `===`, `==`, `!==`, `!=`, `>=`, ``, `
