Custom Eel Helpers

Eel Helpers provide methods that can be used inside of Eel expressions. That is mostly used to extend the capabilities for data-aquisition and processing of Fusion.

#Define the class

The first step is to create the EelHelper class. Every Helper has to implement the interface Neos\Eel\ProtectedContextAwareInterface.

Classes/Eel/Helper/ExampleHelper.php
<?php
declare(strict_types=1);

namespace Vendor\Site\Eel\Helper;

use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;

class ExampleHelper implements ProtectedContextAwareInterface {

    /**
     * Wrap the incoming string in curly brackets
     *
     * @param $text string
     * @return string
     */
    public function wrapInCurlyBrackets(string $text) {
        return '{' . $text . '}';
    }

    /**
     * All methods are considered safe, i.e. can be executed from within Eel
     *
     * @param string $methodName
     * @return boolean
     */
    public function allowsCallOfMethod(string $methodName) {
        return true;
    }
}

To make sure that the class is found, you need to define the composer autoloading in the packages composer.json. We recommend to use PSR-4, like this:

composer.json
{
    "name": "vendor/site",
    "type": "neos-site",
    "require": {
        ...
    }
    "autoload": {
        "psr-4": {
            "Vendor\\Site\\": "Classes"
        }
    },
    ...
}

#Register the helper

Afterwards the name of the Helper has to be registered for usage in Fusion in the Settings.yaml of the package:

Configuration/Settings.yaml
Neos:
  Fusion:
    defaultContext:
      'Vendor.Site.Example': 'Vendor\Site\Eel\Helper\ExampleHelper'

#Usage

In Fusion you can call the methods of the helper inside of EelExpressions:

fusion
exampleEelValue = ${Vendor.Site.Example.wrapInCurlyBrackets('Hello World')}