You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 v7.7.25自定义插件在后端不显示问题求助

嘿,我来帮你搞定TYPO3 v7.7.25上这个自定义内容元素的开发!咱们一步步来实现你的需求——在后端添加可选内容元素,并且它的HTML模板只包含PHP echo语句。

1. 先补全你的emconf.php配置

你给出的配置片段不完整,先把它补全成完整的emconf.php文件,放在扩展的根目录下:

<?php
$EM_CONF[$_EXTKEY] = [
    'title' => 'Robert PHP',
    'description' => 'An extension to use PHP.',
    'category' => 'plugin',
    'author' => 'John Doe',
    'author_company' => 'John Doe Inc.',
    'author_email' => 'john.doe@example.com',
    'state' => 'alpha',
    'clearCacheOnLoad' => true,
    'version' => '1.0.0',
    'constraints' => [
        'depends' => [
            'typo3' => '7.7.0-7.7.99',
        ],
        'conflicts' => [],
        'suggests' => [],
    ],
];

2. 注册自定义内容元素

接下来需要在ext_tables.php和ext_localconf.php里注册你的内容元素,让TYPO3后端能识别它。

在ext_localconf.php中配置内容元素的渲染

<?php
if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}

// 注册内容元素到后端新建内容向导
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
    mod.wizards.newContentElement.wizardItems.common.elements.tx_robertphp_phecho {
        icon = ' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('robert_php') . 'Resources/Public/Icons/ContentElement.png
        title = PHP Echo Content Element
        description = A content element that uses PHP echo in its template
    }
    mod.wizards.newContentElement.wizardItems.common.show := addToList(tx_robertphp_phecho)
');

// 配置内容元素的模板路径
$GLOBALS['TYPO3_CONF_VARS']['FE']['tt_content']['types']['tx_robertphp_phecho']['templateRootPaths'][10] = 
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('robert_php') . 'Resources/Private/Templates/';

在ext_tables.php中定义TCA(内容类型配置)

<?php
if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}

// 定义内容元素的字段展示
$GLOBALS['TCA']['tt_content']['types']['tx_robertphp_phecho'] = [
    'showitem' => '
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
            --palette--;;general,
            header;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:header.ALT.html_formlabel,
            bodytext;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext.ALT.html_formlabel,
        --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
            --palette--;;frames,
            --palette--;;appearanceLinks,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
            --palette--;;language,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
            --palette--;;hidden,
            --palette--;;access,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
            categories,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes,
            rowDescription,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended,
    ',
    'columnsOverrides' => [
        'bodytext' => [
            'config' => [
                'enableRichtext' => false,
                'type' => 'text',
            ],
        ],
    ],
];

// 把内容元素注册到TYPO3系统
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
    [
        'PHP Echo Element',
        'tx_robertphp_phecho',
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('robert_php') . 'Resources/Public/Icons/ContentElement.png'
    ],
    'CType',
    'robert_php'
);

3. 创建内容元素的模板文件

按照你要求的“仅包含PHP echo语句”,咱们创建一个模板来输出后端输入的文本内容。

在扩展目录下创建路径:Resources/Private/Templates/ContentElement/PhEcho.html,文件内容写:

<?php echo $this->data['bodytext']; ?>

4. 测试和收尾

做完以上步骤后,记得:

  • 登录TYPO3后端,清除全部缓存(系统 > 清除缓存 > 全部清除)
  • 新建或编辑页面,添加内容元素时就能看到你定义的「PHP Echo Element」了
  • 在后端输入bodytext内容后,前端会直接渲染模板里的PHP echo结果

注意:TYPO3 v7.7.25是比较老旧的版本,全程要遵循这个版本的API规范,别用后续版本的新功能哦!

内容的提问来源于stack exchange,提问作者user3182532

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:10:23