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

Typo3 9.5:如何为新建页面类型添加自定义字段

在TYPO3 9.5自定义页面类型的标题下方添加新字段

步骤1:新增数据库字段(若需自定义字段)

如果要添加的是全新字段,先在你的扩展的ext_tables.sql里写入字段定义:

ALTER TABLE pages ADD COLUMN my_custom_field varchar(255) DEFAULT '' NOT NULL;

保存后进入TYPO3后台「维护」模块执行数据库更新,确保字段被添加到pages表。

步骤2:注册字段到TCA

在你的扩展的Configuration/TCA/Overrides/pages.php文件中,注册新字段的TCA配置:

<?php
defined('TYPO3_MODE') || die();

// 注册新字段到pages表的TCA
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'pages',
    [
        'my_custom_field' => [
            'label' => 'LLL:EXT:my_ext/Resources/Private/Language/locallang_db.xlf:pages.my_custom_field',
            'config' => [
                'type' => 'input',
                'size' => 50,
                'eval' => 'trim',
            ],
        ],
    ]
);

替换my_ext为你的扩展key,my_custom_field为字段名,可根据需求调整config的类型(如textarea、select等)。

步骤3:调整字段位置到标题下方

找到你自定义页面类型的ID(比如之前创建的是99),在同一个pages.php文件中,修改该页面类型的字段展示顺序,把新字段插入到title后面:

// 针对自定义页面类型ID=99,将新字段插入到标题下方
$pageTypeShowItem = $GLOBALS['TCA']['pages']['types'][99]['showitem'] ?? $GLOBALS['TCA']['pages']['types']['default']['showitem'];
$GLOBALS['TCA']['pages']['types'][99]['showitem'] = str_replace(
    'title,',
    'title, my_custom_field,',
    $pageTypeShowItem
);

如果你的自定义页面类型没有单独配置showitem,会自动使用default类型的配置,上述代码可兼容这种情况。

步骤4:配置语言标签(可选但推荐)

在你的扩展的Resources/Private/Language/locallang_db.xlf中添加字段的多语言标签:

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0">
    <file source-language="en" datatype="plaintext" original="messages">
        <header/>
        <body>
            <trans-unit id="pages.my_custom_field">
                <source>My Custom Field</source>
                <target>我的自定义字段</target>
            </trans-unit>
        </body>
    </file>
</xliff>

最后一步:清除缓存

进入TYPO3后台点击顶部「清除缓存」按钮(包含配置缓存),再打开自定义页面类型的编辑界面,就能看到标题下方的新字段了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 17:20:27