Contentelements with typoscript
Why actually
Many of the developers in the TYPO3 environment have a deep aversion to typoscript and try to avoid this part of TYPO3 as much and as well as possible.
However, the excesses I have seen in the past 10 years are frightening. Instead of using a few lines of typoscript, elaborate controllers were programmed just to re-implement functions that are available through getText.
In this article I would like to show how you can actually implement powerful elements very easily and quickly with typoscript and the TYPO3 board tools.
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Utility\GeneralUtility;
call_user_func(function ($extKey = 'site_provider') {
$register = GeneralUtility::makeInstance(\MST\MstYaml2Tca\Tca\Registry::class);
$register->loadFile($extKey, GeneralUtility::getFileAbsFileName('EXT:' . $extKey . '/Configuration/Yaml/tt_content.yaml'));
});
contentElements:
# group id
additional_elements:
# group title
title: "Additional Elements"
# list of elements
elements:
# element id
additional_text:
title: "Additional Text"
description: "This element is used to add additional text to the page."
icon: "content-text"
config:
showitem:
-
title: "LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general"
fields:
- "--palette--;;general"
- "--palette--;;header"
- "bodytext"
-
title: "LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance"
fields:
- "--palette--;;frames"
-
title: "LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access"
fields:
- "--palette--;;hidden"
- "--palette--;;access"
mst_yaml2tca
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
call_user_func(function ($extKey = 'site_provider') {
ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Additional Text',
'additional_text',
'content-text',
'additional_elements',
],
);
$GLOBALS['TCA']['tt_content']['types']['additional_text'] = [
'showitem' => '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,--palette--;;general,--palette--;;header,bodytext,--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,--palette--;;frames,--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,--palette--;;hidden,--palette--;;access'
];
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['additional_text'] = 'content-text';
});
tt_content.additional_text =< lib.contentElement
tt_content.additional_text {
layoutRootPaths.20 = EXT:site_provider/Resources/Private/Layouts/
partialRootPaths.20 = EXT:site_provider/Resources/Private/Partials/
templateRootPaths.20 = EXT:site_provider/Resources/Private/Templates/
template = AdditionalText
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="Main">
<f:format.html>{data.bodytext}</f:format.html>
</f:section>
</html>
Comments
No Comments