【问题标题】:Configure the Backend fields in typo3在typo3中配置后端字段
【发布时间】:2026-02-05 21:40:01
【问题描述】:

我正在使用 Typo3 V8 而且我需要在 BE 中添加一些额外的字段,所以我创建了一个扩展,允许我添加额外的字段并且它工作正常。

我的问题是 所有字段都显示在所有页面中 某些字段不应出现在所有页面中

例如,我的主页包含一个滑块,因此在 BE 中我有用于上传图像的字段,但在其他页面中我不需要显示这些字段。

【问题讨论】:

    标签: typo3 typoscript


    【解决方案1】:

    您可以添加具有额外字段的特殊 doktype。

    假设它是 doktype 163,然后在ext_localconf.php 中添加:

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
      'options.pageTree.doktypesToShowInNewPageDragArea := addToList(163)'
    );
    

    将其添加到页面树上方的页面类型列表中。

    在同一个文件中注册 doktype 的图标:

    \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
      \TYPO3\CMS\Core\Imaging\IconRegistry::class
    )->registerIcon(
      'apps-pagetree-mytype',
      TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
      [
        'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/Mytype.svg',
      ]
    );
    

    (当然你需要添加你的 svg 图片或者使用不同的图标提供者来注册一个位图)

    Configuration/TCA/Overrides/pages.php 输入:

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
      'pages',
      'doktype',
      [
        'Page type name',
        163,
        'apps-pagetree-mytype'
      ],
      '1',
      'after'
    );
    
    $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][163] = 'apps-pagetree-mytype';
    

    不是通过调用\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes() 添加自定义字段,而是通过以下方式添加它们:

    $GLOBALS['TCA']['pages']['types'][163]['showitem'] =
      $GLOBALS['TCA']['pages']['types'][\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]['showitem']
      . 'the list with your new fields';
    

    这基本上是从默认页面类型复制字段并将它们添加到您的自定义 doktype。

    当然,在 XLIFF 文件中包含页面类型的名称并在代码中将 doktype 编号作为常量会更好,但这是由您添加的。

    根据 doktype,您可以渲染新字段的用途。 希望这是添加页面类型的完整设置列表:-)

    【讨论】:

      最近更新 更多