menu

Custom Eel Helpers

Support the documentation

This documentation was written by volunteers. Please help support our effort:

Help us improve the documentation

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.

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($text) {
        return '{' . $text . '}';
    }

    /**
     * All methods are considered safe, i.e. can be executed from within Eel
     *
     * @param string $methodName
     * @return boolean
     */
    public function allowsCallOfMethod($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:

{
    "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:

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:

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