PHPackages                             salesforce/handlebars-php - 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. salesforce/handlebars-php

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

salesforce/handlebars-php
=========================

Handlebars processor for php

3.0.1(3y ago)80713.2k—7.4%33[5 PRs](https://github.com/salesforce/handlebars-php/pulls)11MITPHPPHP &gt;=5.4.0

Since Nov 19Pushed 1y ago6 watchersCompare

[ Source](https://github.com/salesforce/handlebars-php)[ Packagist](https://packagist.org/packages/salesforce/handlebars-php)[ Docs](http://www.github.com/salesforce/handlebars-php)[ RSS](/packages/salesforce-handlebars-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (13)Used By (11)

[![PHPUnit](https://github.com/salesforce/handlebars-php/actions/workflows/ci.yml/badge.svg)](https://github.com/salesforce/handlebars-php/actions/workflows/ci.yml)

---

\#handlebars-php

---

#### A simple, logic-less, yet powerful templating engine for PHP

[](#a-simple-logic-less-yet-powerful-templating-engine-for-php)

---

Name: **handlebars-php**

License: MIT

Requirements: PHP &gt;= 5.4

---

About Handlebars
----------------

[](#about-handlebars)

Handlebars provides the power necessary to let you build semantic templates effectively with no frustration, that keep the view and the code separated like we all know they should be.

Fork of: [Handlebars.php by XaminProject](https://github.com/mardix/Handlebars)

Handlebars, is the PHP port of [Handlebars.js](http://handlebarsjs.com/)

---

Install Handlebars
------------------

[](#install-handlebars)

You can just download Handlebars.php as is, or with Composer.

To install with composer, add the following in the require key in your **composer.json** file

`"salesforce/handlebars-php": "1.*"`

composer.json

```
{
    "name": "myapp/name",
    "description": "My awesome app name",
    "require": {
        "salesforce/handlebars-php": "1.*"
    }
}
```

---

Getting Started
---------------

[](#getting-started)

At the minimum, we are required to have an array model and a template string. Alternatively we can have a file containing handlebars (or html, text, etc) expression.

#### Template

[](#template)

Handlebars templates look like regular HTML, with embedded handlebars expressions.

Handlebars HTML-escapes values returned by a {{expression}}.

```

  {{title}}

    Hello, my name is {{name}}

```

The string above can be used as is in your PHP file, or be put in a file (ie: */templates/main.tpl*), to be called upon rendering.

#### PHP file

[](#php-file)

Now the we've created our template file, in a php file (index.php) we'll create the data to passed to the model. The model is a key/value array.

Below we are going to create the Handlebars object, set the partials loader, and put some data in the model.

**/index.php**

```
