
Every second project needs a “teaser” box: a headline, a short text and one link with its own label. For years my reflex was to install an extension for that. In TYPO3 v14 I do not need one anymore. The core does most of the boring parts by itself, and what is left fits in three small files of the sitepackage.
This post builds exactly that teaser, step by step, and points out which part changed in which version, because a lot of old tutorials still show the v11 way.
Problems I faced
The old recipe had many places to touch: a column definition in ext_tables.sql, a TCA override, a wizard entry in page TSconfig under mod.wizards.newContentElement, the general/access/language tabs copied into every showitem, TypoScript for rendering and then some typolink fiddling in the template. Forget one and the element is either invisible in the wizard or the database compare complains. Since v13 most of that is gone:
- Database columns are created from TCA (Feature #101553, v13.0), so no
ext_tables.sqlfor normal fields. - The new content element wizard reads its entries from the CType items in TCA (Feature #102834, v13.0).
- System fields like CType, colPos, hidden, language and access are added to every content type automatically (Feature #104814, v13.3).
- The
record-transformationdata processor (v13.2) gives the template aRecordobject, and link fields arrive as a typed object (v13.3).
Solution
I assume a sitepackage with the extension key sitepackage and a site set that depends on typo3/fluid-styled-content. The new CType is called sitepackage_teaser.
Step 1: TCA override
Create Configuration/TCA/Overrides/tt_content.php. It adds two fields, the CType item and the type definition:
<?php
declare(strict_types=1);
use TYPO3CMSCoreUtilityExtensionManagementUtility;
defined('TYPO3') or die();
$ll = 'LLL:EXT:sitepackage/Resources/Private/Language/locallang_db.xlf:';
ExtensionManagementUtility::addTCAcolumns('tt_content', [
'tx_sitepackage_link' => [
'exclude' => true,
'label' => $ll . 'tt_content.tx_sitepackage_link',
'config' => [
'type' => 'link',
'allowedTypes' => ['page', 'url', 'record'],
],
],
'tx_sitepackage_link_label' => [
'exclude' => true,
'label' => $ll . 'tt_content.tx_sitepackage_link_label',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 60,
],
],
]);
ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'label' => $ll . 'tt_content.CType.sitepackage_teaser',
'description' => $ll . 'tt_content.CType.sitepackage_teaser.description',
'value' => 'sitepackage_teaser',
'icon' => 'content-text-teaser',
'group' => 'default',
],
'text',
'after'
);
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['sitepackage_teaser'] = 'content-text-teaser';
$GLOBALS['TCA']['tt_content']['types']['sitepackage_teaser'] = [
'showitem' => '
--palette--;;headers,
bodytext,
tx_sitepackage_link,
tx_sitepackage_link_label,
--div--;core.form.tabs:appearance,
--palette--;;frames,
--palette--;;appearanceLinks,
--div--;core.form.tabs:extended,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
],
],
],
];A few notes, because this is where I lost time:
- The
showitemlist has no general, language or access tab. TYPO3 adds those since v13.3. If you copy them from an old element, they are removed and added again at the right place, so nothing breaks, but there is no reason to keep them. - The tab labels
core.form.tabs:appearanceand friends are the short form introduced in v14.0. In v13 you write the longLLL:EXT:…path. content-text-teaseris an icon that ships with the core, so no icon registration is needed. The itemiconis used by the wizard,typeicon_classesby the page module and the list.- Do not call
ExtensionManagementUtility::addPlugin()with the v13 signature for this. In v14.3 it takes only the item and an optional FlexForm, and it is meant for plugins. For a plain content type,addTcaSelectItem()says what you mean.
Add the four labels to locallang_db.xlf, flush caches and run vendor/bin/typo3 extension:setup. It creates both columns from the TCA alone. The element now shows up in the wizard in the “default” tab, right after “Text”, with its description. No page TSconfig at all.
Step 2: Rendering TypoScript in the site set
fluid_styled_content renders its elements with lib.contentElement, a FLUIDTEMPLATE with template, partial and layout paths. I add one more template path and register the new type in the setup.typoscript of my site set:
lib.contentElement {
templateRootPaths.200 = EXT:sitepackage/Resources/Private/ContentElements/Templates/
}
tt_content.sitepackage_teaser =< lib.contentElement
tt_content.sitepackage_teaser {
templateName = Teaser
}Because my set lists typo3/fluid-styled-content as a dependency, its TypoScript is loaded after the core one and the extra path wins. If you prefer settings over TypoScript, the set of fluid_styled_content also has a setting styles.templates.templateRootPath that fills path 10; I like the explicit 200 because I see it in the TypoScript object browser at once.
Step 3: The Fluid template
Create Resources/Private/ContentElements/Templates/Teaser.html:
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="Main">
<div class="teaser">
<div class="teaser__text">
{record -> f:render.text(field: 'bodytext')}
</div>
<f:if condition="{record.tx_sitepackage_link.url}">
<f:link.typolink parameter="{record.tx_sitepackage_link}" class="teaser__link">
<f:if condition="{record.tx_sitepackage_link_label}"
then="{record.tx_sitepackage_link_label}"
else="Read more" />
</f:link.typolink>
</f:if>
</div>
</f:section>
</html>The headline comes for free: the Default layout of fluid_styled_content renders the header partial before the Main section, with all the header layout options editors know.
Step 4: The data processor for the link
Where does {record} come from? From the record-transformation data processor. It turns the raw row into a Record object that only exposes the fields of this content type and converts values by their TCA type. For a field of type => 'link' you get a TypolinkParameter object with url, target, class and title, and f:link.typolink accepts that object directly. That is why the condition checks .url: the object itself is always there, even when the field is empty.
In TYPO3 14.3 you do not have to add the processor yourself. Open Configuration/TypoScript/Helper/ContentElement.typoscript of fluid_styled_content and you will see that lib.contentElement already runs record-transformation, which is also why the core templates use {record} and the f:render.text ViewHelper (new in 14.2). On v13 you add it to your element:
tt_content.sitepackage_teaser {
templateName = Teaser
dataProcessing {
10 = record-transformation
}
}and replace f:render.text with <f:format.html>{record.bodytext}</f:format.html>, because that ViewHelper does not exist there yet.
Step 5: Check it
- Create a teaser in the page module, pick a page link and leave the label empty. You should see “Read more”.
- Switch the link to an external URL with a target in the link browser. The rendered
<a>must carry the target. - Clear the link field. The link must disappear, not render an empty
<a>. - Translate the element. The language tab is there although we never wrote it.
When I would still reach for an extension
For one or two simple elements, the core way is shorter than learning a tool. When a project has twenty elements with repeating fields, inline child records and many editors, a content-type extension that generates TCA from a YAML file starts to pay back. That is a decision per project, not a religion. For my own sites the three files above are enough, and I understand every line in them, which is worth a lot during the next upgrade.
Feedbacks are the champion’s breakfast, so drop a comment if your teaser needed something I did not cover.
2 comments
Anna Achen
Nice guide! Creating custom content elements without relying on extra extensions gives developers more flexibility and control over their TYPO3 projects. It is especially useful when you want to keep the setup clean and tailored to specific needs.
Wolf Gang Weber
Interesting article! TYPO3 v14 makes it easier to create custom content elements without relying on additional extensions, giving developers more flexibility and control over their websites. As TYPO3 continues to evolve, AI-powered features can further enhance the user experience.