我正在尝试使用以作曲家模式安装的 TYPO3 和使用sitepackagebuilder生成的站点包创建 ViewHelper 。
应该正确配置自动加载,但我得到的唯一一件事是一条错误消息,即无法找到 ViewHelper:
#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.
重现步骤
- 在作曲家模式下安装 TYPO3(最新版本 9.2.1)
- 使用https://sitepackagebuilder.com创建一个站点包- 简单配置,'foo' 作为公司名称,'bar' 作为扩展键(见下面的截图)
SomeViewHelper
在下创建一个简单的类Classes/ViewHelpers/
修改下面的模板
Page/Default
以包含SomeViewHelper
(按照docs.typo3.org中的示例){namespace foobar=Foo\Bar\ViewHelpers} <foobar:some />
在 TYPO3 中创建一个包含简单内容的新根页面并包含
bar
扩展名(模板 > 包含)
代码的自动加载应该由 sitepackagebuilder 生成的composer.json
/ext_emconf.php
文件处理。
截屏
代码
SomeViewHelper.php
<?php
namespace Foo\Bar\ViewHelpers;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
class SomeViewHelper extends AbstractViewHelper
{
public function render() {
return 'Hello World';
}
}
页面/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>
在文档顶部声明命名空间也无济于事
<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>
作曲家.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' => 'jd@foo.com',
'author_company' => 'foo',
'version' => '1.0.0',
];