I'm trying to create a ViewHelper with a TYPO3 which was installed in composer mode and a site package which was generated with the sitepackagebuilder.
The autoloading should be configured correctly, nevertheless the only thing I'm getting is an error message, that the ViewHelper cannot be found:
#1407060572: Fluid parse error in template Standard_action_Default_9cc8c1fca58b49310db5d43052e614cefdb1c728, line 5 at character 6. Error: The ViewHelper "<foobar:some>" could not be resolved. Based on your spelling, the system would load the class "Foo\Bar\ViewHelpers\SomeViewHelper", however this class does not exist. (error code 1407060572). Template source chunk: <foobar:some /> (More information)
TYPO3Fluid\Fluid\Core\Parser\Exception thrown in file
/var/www/html/vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php in line 157.
Steps To Reproduce
- install TYPO3 in composer mode (newest version 9.2.1)
- create a site package with https://sitepackagebuilder.com - simple configuration, 'foo' as company name and 'bar' as extension key (see screenshot below)
- create a simple class
SomeViewHelperunderClasses/ViewHelpers/ modify the template under
Page/Defaultto contain theSomeViewHelper(following the example from docs.typo3.org){namespace foobar=Foo\Bar\ViewHelpers} <foobar:some />create a new root page in TYPO3 with simple content and include the
barextension (Template > Includes)
The autoloading of the code should be handled by the composer.json/ext_emconf.php files which are generated by the sitepackagebuilder.
Screenshot
Code
SomeViewHelper.php
<?php
namespace Foo\Bar\ViewHelpers;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
class SomeViewHelper extends AbstractViewHelper
{
public function render() {
return 'Hello World';
}
}
Page/Default.html
<f:layout name="Default" />
<f:section name="Main">
{namespace foobar=Foo\Bar\ViewHelpers}
<foobar:some />
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
</f:section>
also declaring the namespace at the top of the document did not help
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:foobar="http://typo3.org/ns/Foo/Bar/ViewHelpers">
<f:layout name="Default" />
<f:section name="Main">
<foobar:some />
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
</f:section>
</html>
composer.json
{
"name": "foo/bar",
"type": "typo3-cms-extension",
"description": "",
"homepage": "https://www.foo.com",
"license": ["GPL-2.0-or-later"],
"keywords": ["TYPO3 CMS"],
"version": "1.0.0",
"require": {
"typo3/cms-core": "^8.7 || ^9.0",
"typo3/cms-rte-ckeditor": "^8.7 || ^9.0",
"typo3/cms-fluid-styled-content": "^8.7 || ^9.0"
},
"autoload": {
"psr-4": {
"Foo\\Bar\\": "Classes/"
}
}
}
ext_emconf.php
<?php
/**
* Extension Manager/Repository config file for ext "bar".
*/
$EM_CONF[$_EXTKEY] = [
'title' => 'Bar',
'description' => '',
'category' => 'templates',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-9.5.99',
'fluid_styled_content' => '8.7.0-9.5.99',
'rte_ckeditor' => '8.7.0-9.5.99'
],
'conflicts' => [
],
],
'autoload' => [
'psr-4' => [
'Foo\\Bar\\' => 'Classes'
],
],
'state' => 'stable',
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 1,
'author' => 'John Doe',
'author_email' => '[email protected]',
'author_company' => 'foo',
'version' => '1.0.0',
];
