Use custom Fluid ViewHelpers without having to import the namespace first
Use custom Fluid ViewHelpers in Neos Flow without import statement
When using the Fluid rendering engine together with Neos Flow, you can use Fluid’s built in and your own custom viewhelpers.
Fluid ViewHelpers are by default available with the <f:[viewhelper-name]>
syntax – such as <f:format.date date="{dateObject}">
. This syntax is possible because, the f
namespace is automatically imported.
But with the Neos Flow adaptor for Fluid, the ViewHelpers of all packages is available in the syntax
<vendor.package:[viewhelper-name]>
In this case vendor.package
is the package name.
Example
Create a ViewHelper named HelloWorldViewHelper, located in the Classes/ViewHelpers/
folder.
copy/paste the code here
<?php namespace Vendor\Package\ViewHelpers; use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper; class MenuViewHelper extends AbstractViewHelper { public function render() { return 'Hello world'; } }
Now, enter the following HTML on your Fluid Template
<vendor.package:helloWorld />
And you will have the output Hello world
You can add arguments, rendering of children elements and everything you want.