一个用于创建自定义嵌套内容元素的 TYPO3 扩展
At b13, we've long supported gridelements, for which we are thankful, and have used this extension with great pleasure in the past.
However, we had our pain points in the past with all the solutions we've evaluated and worked with. These are our reasons:
colPos field and dislike any fixed value that isn't fully compatible with TYPO3 Core.Install this extension via composer req b13/container or download it from the TYPO3 Extension Repository and activate
the extension in the Extension Manager of your TYPO3 installation.
Once installed, add a custom content element to your site package or theme extension (see "Adding your container element").
Configuration/TCA/Overrides/tt_content.php as new Content TypeSee EXT:container_example for a simple example of a custom container.
This is an example of creating a two-column container. The code snippet goes into a file in your site package or theme extension in the folder Configuration/TCA/Overrides/. The file can have any name, but it is good practice to name it according to the database table it relates to. In this case, this would be tt_content.php.
…| Method name | Description | Parameters | Default |
|---|---|---|---|
setIcon |
icon file, or existing icon identifier | string $icon |
'EXT:container/Resources/Public/Icons/Extension.svg' |
setBackendTemplate |
Template for backend view | ?string $backendTemplate |
EXT:container/Resources/Private/Templates/Container.html' |
disableBackendTemplate |
Disables the backend template for this CType (shortcut for setBackendTemplate(null)), if you want another preview mechanism (e.g. EXT:backenlayout) |
- | - |
setGridTemplate |
Template for grid | string $gridTemplate |
'EXT:container/Resources/Private/Templates/Grid.html' |
setGridPartialPaths / addGridPartialPath |
Partial root paths for grid | array $gridPartialPaths / string $gridPartialPath |
['EXT:backend/Resources/Private/Partials/', 'EXT:container/Resources/Private/Partials/'] |
setGridLayoutPaths |
Layout root paths for grid | array $gridLayoutPaths |
[] |
setSaveAndCloseInNewContentElementWizard |
saveAndClose for new content element wizard | bool $saveAndCloseInNewContentElementWizard |
true |
setRegisterInNewContentElementWizard |
register in new content element wizard | bool $registerInNewContentElementWizard |
true |
setGroup |
Custom Group (used as optgroup for CType select, and as tab in New Content Element Wizard). If empty, "container" is used as tab and no optgroup in CType is used. | string $group |
'container' |
setRelativeToField |
Add item relative to existing field. | string $relativeToField |
'' |
setRelativePosition |
Valid keywords: 'before', 'after', 'replace'. |
string $relativeToField |
'' |
setDefaultValues |
Default values for the newContentElement.wizardItems | array $defaultValues |
[] |
Notes:
allowed, disallowed, and maxitems in the column configurationshowitem for this CType (header)$GLOBALS['TCA']['tt_content']['containerConfiguration'][] for further usageResources/Public/IconsThe TypoScript is necessary to define the rendering of the container in the frontend. Normally, you will place it in your site package or theme extension near where you define other stuff regarding your content elements.
templateRootPaths must be adapted to reflect the path of the HTML files in your site package or theme extension.
// default/general configuration (will add 'children_' variable to processedData for each colPos in container
tt_content.b13-2cols-with-header-container data['uid']`` | ``?int`` |
| colPos | colPos of children to to process | empty, all children are processed (as children_) | ?int |
| as | variable to use for proceesedData (only if colPos is set) | children | ?string |
| skipRenderingChildContent | do not call ContentObjectRenderer->render() for children, (renderedContent in child will not exist) | empty | ?int |
The HTML template file goes in the folder you defined in your TypoScript above (see templateRootPaths). It's important to name it exactly as defined in templateName in TypoScript, in this case, 2ColsWithHeader.html. The file name is case-sensitive!
{record.header}
{record.renderedContent}
{record.header}
{record.renderedContent}
With explicit colPos defined use {children_200|201} as set in the example above
for TYPO3 v14 or higher you can use the ConentAreaProcessor Automatically detects if content element has container columns adds them lazily to the content variable. The ContentArea can be used in f:render.contentArea or f:render.record ViewHelper
tt_content.b13-2cols-with-header-container data['uid']`` | ``?int`` |
| as | variable to use for proceesedData | content | ?string |
{record -> f:render.record()}
gridTemplate)Change view object, e.g., add variables to view or change paths
_ used in the data-colpos attribute in the wrapping CE-div Element (instead of just the colPos as in the PageLayoutView)_ parameter is resolved to tx_container_parent and colPos value in DataHandler hookscolPos values so site owners build their own elements, no fixed colPos given, so no interference with existing solutionsCTypeIn case you want to migrate your existing hierarchical contents (e.g. EXT:gridelements) to EXT:container it's best to know a bit about the internal structure.
pid should always match its container CEs pidtx_container_parent points its container CEs uidsorting is pid-wide (and thus logically consistent for all CEs within the same colPos)l18n_parent points obviously to its translation origin (if it has one)tx_container_parent doesn't point to the translated parent (as you would assume) but to the translation origintx_gridelements_children)Here's a typical use case of a translated container and its child CEs.
…There are several CLI commands to check/fix the integrity of the containers and their children.
# Check the sorting of container children
vendor/bin/typo3 container:sorting
# Fix the sorting of container children on page 123
vendor/bin/typo3 container:sorting --apply 123
# Check the sorting of records in page colPos
vendor/bin/typo3 container:sorting-in-page
# ??
bin/typo3 container:fixLanguageMode
bin/typo3 container:fixContainerParentForConnectedMode
bin/typo3 container:deleteChildrenWithWrongPid
bin/typo3 container:deleteChildrenWithNonExistingParent
bin/typo3 container:deleteChildrenWithUnusedColPosYou can run our test suite for this extension yourself:
composer installBuild/Scripts/runTests.sh -s unitBuild/Scripts/runTests.sh -s functionalBuild/Scripts/runTests.sh -s acceptanceSee Tests/README.md on how to run the tests locally (like how github-actions runs the tests).
To assure coding guidelines are fullfilled:
php -d memory_limit=2G .Build/bin/phpstan analyse -c Build/phpstan14.neonphp -d memory_limit=2G .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=noThis extension was created by Achim Fritz in 2020 for b13 GmbH, Stuttgart.
Find examples, use cases, and best practices for this extension in our container blog series on b13.com.
Find more TYPO3 extensions we have developed that help us deliver value in client projects. As part of our work, we focus on testing and bes
暂无开放 Issues,或尚未同步最近议题。