PHPackages                             hphio/farret - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. hphio/farret

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hphio/farret
============

Find And Recursively Replace Email Templates - generate email templates fast and easy.

v1.0.1(3y ago)02.8k—0%MITPHPPHP ^8.1

Since Jul 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mjmunger/farret)[ Packagist](https://packagist.org/packages/hphio/farret)[ Docs](https://github.com/mjmunger/farret)[ RSS](/packages/hphio-farret/feed)WikiDiscussions master Synced 1mo ago

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

farret
======

[](#farret)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/935fb8233b0ec47cae13b2f17305979aea37070eb7701515ae6d4725bf0f10c5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a6d756e6765722f6661727265742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mjmunger/farret/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/747f86c32a163ed96e173dcb411f1342cc119231ede54b428775ee4aac4b72ae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a6d756e6765722f6661727265742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mjmunger/farret/?branch=master)[![Build Status](https://camo.githubusercontent.com/f7f06f54f624f5d9c0c3ad682bdd617e9cefb716c104f09579bc4fd8d470809d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a6d756e6765722f6661727265742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mjmunger/farret/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/de41ab24e365e480d099e5cec86a49499517314b18821fb1da8f9dc6dd6fa51e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a6d756e6765722f6661727265742f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

Find And Recrusively Replace Email Templates

Installation
------------

[](#installation)

`composer require hphio/farret dev-master`

Requirements
------------

[](#requirements)

This was developed on, and intended for PHP v7.0+. It *may* work on lower versions, but YMMV.

Documentation
-------------

[](#documentation)

### How to use this package.

[](#how-to-use-this-package)

This package revolves around a single class, the `Notif`, which represents a notification your system may send out. The Notif is designed to work with PHPMailer, but can be used by itself.

To create an email notification, simply create an html email with the desired look and feel, and insert template tags into the email where appropriate. Then, use code like this to create a fully rendered, well-formed email ready to be sent:

### Template syntax

[](#template-syntax)

There are three types of template tags in farret:

- `{{ TAGS }}`
- `{% HOOKS %}`
- `{% HOOKS|WITH|ARGUMENTS %}`

#### Tags

[](#tags)

A `tag` is a simple placehold where a find and replace operation will substitute the needed information where the tag was added to the email. These substitutions are global, so, using `{{ FIRSTNAME }}` to add "Michael" as the first name of the recipient will happen EVERYWHERE in the template.

The matching engine is rather flexible, and considers the single space between the opening and closing pair of brackets optional. So, having the space (or having them unbalanced) doesn't matter. It will still get replaced.

Example of valid tags:

- `{{FIRSTNAME}}`
- `{{FIRSTNAME }}`
- `{{ FIRSTNAME}}`
- `{{ FIRSTNAME }}`

### Example #1: A Regular notification

[](#example-1-a-regular-notification)

**Create the notif, and tell it where your templates are:**

```
$Notif = new Notif();
$Notif->setTemplateDirectory('/path/to/your/templates');
$Notif->setTemplate('sometemplate');

```

**Tell the notif what template tags to look for, and what they will be replaced with:**

*Use the `addFart` method. ("add Find And Replace Template").*

```
$Notif->addFart('FIRSTNAME', $firstname);
$Notif->addFart('LASTNAME', $lastname);
$Notif->addFart('SOMEURL', $url);

```

**Render the email**

```
$Notif->render();

```

This reads the template, and perofrms all the necessary find and replace operations to fill out the template properly, and the resulting HTML for the email is now available in `$Notif->body`;

#### Hooks

[](#hooks)

A `hook` is a special kind of tag, which expects to perform an operation and substitute the result of that operation at that location in the template. The most common type of hook is the date hook, which is a built-in action in the `Notif` class.

For example, let's say you wanted to have a dynamic copyright statement in your template. The hook `{% YEAR %}` will substitute the current year (2018 as of this writing) at that location in the template.

There are three "magic" hooks that are built in to the `Notif` class, which are:

1. `{% YEAR %}`
2. `{% MONTH %}`
3. `{% DAY %}`

#### Hooks with arguments

[](#hooks-with-arguments)

Internally, hooks use a callback function to do some operation on the provided data. The YEAR, MONTH, and DAY hooks above are actually convenience functions (fascades) to the DATE method of the Notif class, which provide a single argument to that method. (See source code).

So, suppose we want to add the current date in the format `Y-m-d`. We can do that by adding the following hook:

`{% DATE|Y-m-d %}`

When the `Notif` class sees this, it will parse the tag to see that the hook is `DATE` and a single argument `Y-m-d` should be passed to it.

#### Creating custom actions

[](#creating-custom-actions)

Actions rely on callbacks within the class. Let's say you had a need to compute a hash of the current date and put it in the email. You can create this by adding a hook into your template like so:

`{% HASH %}`

Of course, the `Notif` class itself does not support this natively, so the solution is to simple extend the Notif class and add the capabilities:

```
class MyNotif extends Notif
{
    public function makeHash($args) {
        $now = new DateTime();
        return md5sum($now->format("Y-m-d"));
    }
}

```

Now, you would use your customized `MyNotif` class to create your notifications instead of the base `Notif` class. Note that you have to register the hooks with your notification in order for it to work:

```
$MyNotif = new MyNotif();
$MyNotif->render();

```

#### Creating more complex custom actions

[](#creating-more-complex-custom-actions)

In continuing with our example, let's say we needed to perform some operation on a record of data (create a hash of a recipients firstname + the current timestamp). We would extend the original Notif class as we did above, but now, we will use additional template fields as part of the arguments passed to the hook:

```
{% HASH|{{ FIRSTNAME}} %}

```

```
class MyNotif extends Notif
{
    public function makeHash($args) {
        $firstname = $args[0];
        return md5sum($firstname . microtime(true) );
    }
}

```

In this case, the hook is detected, and all the template tags would be resolved prior to executing the callback, which will produce the final hash.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~555 days

Total

4

Last Release

1181d ago

Major Versions

v0.1.1 → v1.0.02023-02-19

PHP version history (2 changes)v0.1.0PHP ^7.0

v0.1.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb09c625c46f0c8bbc7691aaa7efe99f1f567ed534d6f2b3ea7529bf708a72ea?d=identicon)[hphinc](/maintainers/hphinc)

---

Top Contributors

[![mjmunger](https://avatars.githubusercontent.com/u/6370814?v=4)](https://github.com/mjmunger "mjmunger (1 commits)")

---

Tags

emailhtmltemplates

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hphio-farret/health.svg)

```
[![Health](https://phpackages.com/badges/hphio-farret/health.svg)](https://phpackages.com/packages/hphio-farret)
```

###  Alternatives

[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48419.5M75](/packages/soundasleep-html2text)[snowfire/beautymail

Send beautiful html emails with Laravel

1.3k733.1k2](/packages/snowfire-beautymail)[voku/html2text

Only a Fork of -&gt; html2text: Converts HTML to formatted plain text

39335.8k2](/packages/voku-html2text)[yiimaker/yii2-email-templates

Extension for creating of email templates and manage using your site dashboard

9219.4k1](/packages/yiimaker-yii2-email-templates)[osiemsiedem/laravel-autolink

A Laravel package for converting URLs in a given string of text into clickable links.

13126.3k](/packages/osiemsiedem-laravel-autolink)

PHPackages © 2026

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