Search code examples
namespacestypo3fluidtypo3-6.1.x

TYPO3: Write a ViewHelper in an extension with vendor namespace


I have created an extension with plugins in a vendor namespace. Everything works fine so far. All the classes start with a namespace declaration namespace \VENDOR\ExtensionName\... and typo3 autoloads them just fine.

However, the problem starts when I add a ViewHelper. I put this in the \VENDOR\ExtensionName\ViewHelpers namespace. I added the namespace in my Fluid template like so: {namespace ns=VENDOR\ExtensionName\ViewHelpers}. When I call it in the template with <ns:myViewHelper />, I just get an 'Oops ...' error message:

Could not analyse class:VENDOR\ExtensionName\ViewHelpers\MyViewHelperViewHelper maybe not loaded or no autoloader?

The same happens, when I put the ViewHelper in a \TYPO3\... namespace.

How do I correctly implement a ViewHelper in an extension with a vendor namespace?


Solution

  • The namespace declaration must not have a leading backslash.

    Instead having \Vendor\ExtensionName\ViewHelpers; it has to be Vendor\ExtensionName\ViewHelpers;

    http://www.php.net/manual/en/language.namespaces.nested.php