itplusx / flexible-pages
支持自定义页面类型的设置和管理。
Requires
- php: ^8.1
- ext-json: *
- symfony/finder: ^6.2
- typo3/cms-core: ^12.0
- typo3/cms-fluid-styled-content: ^12.0
Requires (Dev)
- mikey179/vfsstream: ^1.4
- namelesscoder/typo3-repository-client: ^1.2
- nimut/testing-framework: ^1.0
- phpunit/phpunit: ^4.7 || ^5.0
Suggests
- friendsoftypo3/headless: Allows headless (json) output of flexible_pages content elements
Replaces
- typo3-ter/flexible-pages: v3.0.0
This package is auto-updated.
Last update: 2024-09-04 16:45:10 UTC
README
TYPO3 扩展 flexible_pages
在 TYPO3 中轻松设置自定义页面类型。
此扩展将 TYPO3 中自定义页面类型的注册简化为使用 YAML 文件的简单设置。
- 功能
- 路线图
- 安装
- 注册自定义页面类型
- 通用前端列表插件 (tx_flexiblepages_pagelist)
功能
✓ 几秒钟内注册自定义页面类型
✓ 使用自定义或已注册的图标
✓ 插件以根据页面类型渲染菜单/页面列表
路线图
- 如果没有注册图标,则使用标签的首字母创建一个通用图标
- 后端模块以配置自定义页面类型。它基本上是 YAML 文件的配置前端
- 启用在页面选择框中设置自定义位置
- 启用按日期排序
- Cli 命令以创建页面类型
- BE 模块
- 列表
- 带有页面类型筛选器的页面列表
- 批量编辑
- 配置
- 在 BE 中配置页面类型
- 列表
- 提供一种优雅的方式来使用附加字段扩展自定义页面类型
1. 安装
1.1 使用 composer
安装
composer require itplusx/flexible-pages
1.2 使用 TYPO3 扩展管理器安装
在 TYPO3 扩展管理器 中使用扩展密钥 flexible_pages
。
2. 注册自定义页面类型
有两种方式可以注册自定义页面类型。
2.1 使用 YAML 配置文件(推荐)
通过 YAML 添加新页面类型最简单的方法是三种不同的可能性存在来添加新的 pageTypes 通过 YAML 文件
2.1.1 使用全局配置目录
与 TYPO3 核心的站点配置一样,也可以在全局配置目录中添加 YAML 文件。
示例
config/
└── flexible_pages/
└── myNewPageType.yaml
└── myOtherPageType.yaml
└── Articles
└── blogArticle.yaml
└── newsArticle.yaml
2.1.2 使用扩展配置目录
第三方扩展也可以使用 flexible_pages
作为添加自定义页面类型的基座。要启用此功能,只需在您的扩展内部 Configuration/Yaml/flexible_pages
中添加一个 YAML 配置文件即可。
示例
your_extensionkey/
└── Configuration/
└── Yaml
└── flexible_pages/
└── myNewPageType.yaml
└── myOtherPageType.yaml
└── Articles
└── blogArticle.yaml
└── newsArticle.yaml
2.1.3 添加自定义路径
除了前两个预定义的目录路径外,还可以定义第三个自定义路径来存储您的自定义 YAML 文件。为此,您可以在 Admin Tools -> Settings -> Extension Configuration -> flexible_pages
中添加自定义路径或在您的 ext_localconf.php
中设置 $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['flexible_pages']['additionalYamlConfigPath']
。
2.1.4 YAML 文件示例
dokType: 87
label: 'My Custom pageType'
iconSet:
defaultIcon:
source: 'EXT:your_ext/Resources/Public/Icons/apps-pagetree-mycustompagetype.svg'
hideInMenuIcon:
identifier: 'apps-pagetree-page-frontend-user-hideinmenu'
rootPageIcon:
source: 'EXT:your_ext/Resources/Public/Icons/apps-pagetree-mycustompagetype-root.svg'
isDraggableInNewPageDragArea: true
2.2 使用 ext_localconf.php
\ITplusX\FlexiblePages\Registry\PageTypesRegistration::registerPageType( 87 'My Custom pageType', [ \ITplusX\FlexiblePages\Configuration\IconSetConfiguration::ICON_TYPE_DEFAULT => [ 'source' => 'EXT:your_ext/Resources/Public/Icons/apps-pagetree-mycustompagetype.svg', ], \ITplusX\FlexiblePages\Configuration\IconSetConfiguration::ICON_TYPE_HIDE_IN_MENU => [ 'identifier' => 'apps-pagetree-page-frontend-user-hideinmenu', ] \ITplusX\FlexiblePages\Configuration\IconSetConfiguration::ICON_TYPE_ROOT_PAGE => [ 'source' => 'EXT:your_ext/Resources/Public/Icons/apps-pagetree-mycustompagetype-root.svg', ] ], 'isDraggableInNewPageDragArea' => true );
2.3 配置
2.3.1 注册参数
2.3.2 图标参数
3. 通用前端列表插件(tx_flexiblepages_pagelist)
flexible_pages 提供了一个通用列表插件,可以根据特定的页面类型来列出页面。此插件的某些设置可以通过用户配置来使其尽可能灵活。
3.1 扩展模板
扩展模板选择字段,可以添加您自己的自定义模板。自定义模板可以通过 PageTS 或 EXTCONF 数组添加。
3.1.1 通过 PageTS 扩展
作为关联数组
tx_flexiblepages {
tx_flexiblepages_pagelist {
templates {
myTemplate = My new template
myTemplate2 = My new template 2
}
}
}
作为数字数组
tx_flexiblepages {
tx_flexiblepages_pagelist {
templates {
0 = My new template
1 = My new template 2
}
}
}
3.1.2 通过 EXTCONF 扩展
作为关联数组
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flexible_pages']['tx_flexiblepages_pagelist']['templates'] = [ 'myTemplate' => 'My new template', 'myTemplate2' => 'My new template 2', ];
作为数字数组
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flexible_pages']['tx_flexiblepages_pagelist']['templates'] = [ 'My new template', 'My new template 2' ];
3.1.3 添加自定义模板文件
在扩展模板配置后,您想添加自定义模板文件。为此,您必须扩展 fluid_styled_content 的 rootPaths。您可以在自己的扩展中通过扩展 lib.contentElement
TypoScript(如此处所述)或使用 flexible_pages 提供的常量。
plugin.tx_flexiblepages.templateRootPath
plugin.tx_flexiblepages.partialRootPath
plugin.tx_flexiblepages.layoutRootPath
最后,您可以在之前指定的 templateRootPath
中添加自定义模板文件。
文件命名
- 当您选择使用关联数组扩展模板时,您的模板文件必须命名为键(例如大驼峰式命名;例如
MyTemplate.html
)。 - 当您选择使用数字数组扩展模板时,您的模板文件必须命名为值(例如大驼峰式命名;例如
MyNewTemplate.html
)。
3.2 扩展 orderBy
可以扩展 orderBy
选择以添加自定义排序字段。例如,如果您为您自定义的页面类型添加了一个新的字段 type
,则在需要时也可以按此字段排序。
为每个添加的自定义 orderBy
项目创建一个升序和降序变体。自定义排序字段可以通过 PageTS 或 EXTCONF 数组添加。
注意:orderBy
项的键必须是数据库中的字段名!不允许使用数字数组。
3.2.1 通过 PageTS 扩展
tx_flexiblepages {
tx_flexiblepages_pagelist {
orderBy {
type = Type
}
}
}
3.2.2 通过 EXTCONF 扩展
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flexible_pages']['tx_flexiblepages_pagelist']['orderBy'] = [ 'type' => 'Type' ];
4. 工作示例
有关工作示例,请参阅 EXT:flexible_news。在那里您可以看到如何轻松地
- 设置具有特殊图标和名称的新页面类型
- 扩展 tx_flexiblepages_pagelist CE 的模板选择