[英]TYPO3 - Error by creating custom content element
我需要您的幫助來創建自定義內容元素。 我使用TYPO3版本。 10.4.21 並且我添加了擴展(fluid_styled_content 和 sitepackage)。
我可以為下拉列表創建一個向導和內容類型 (CType),但是如果我讓在前端 (websie) 上顯示我的內容元素,則會發生錯誤: Oops, an error occurred! Code: 202111110917379495faab
Oops, an error occurred! Code: 202111110917379495faab
。
也許模板路徑有錯誤......但我不知道如何修復它。
我從現在開始:
CREATE TABLE tt_content (
code_language text DEFAULT '' NOT NULL
);
// Add dropdown for code language to TCA.
$additionalColumns = [
'code_language' => [
'label' => 'LLL:EXT:my_sitepackage_for_flipbox/Resources/Private/Language/locallang_db.xlf:tt_content.code_language',
'config' => [
'type' => 'select',
'default' => '',
'itemsProcFunc' => 'B13\\my_sitepackage_for_flipbox\\DataProvider\\CodeLanguages->getAll',
'renderType' => 'selectSingle',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $additionalColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'code_language',
'my_sitepackage_for_flipbox',
'before:bodytext'
);
// Adds the content element to the "CType" dropdown for NewContentElement
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
array(
'1 Column Flipbox',
'oneColumnFlipbox',
'EXT:my_sitepackage_for_flipbox/Resources/Public/Icons/T3Icons/content/content-carousel-image.svg'
),
'CType',
'my_sitepackage_for_flipbox',
);
// Configure the default backend fields for the content element
$frontendLanguageFilePrefix = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:';
$GLOBALS['TCA']['tt_content']['types']['oneColumnFlipbox'] = [
'showitem' => '
--palette--;' . $frontendLanguageFilePrefix . 'palette.general;general,
--palette--;;headers,
bodytext;' . $frontendLanguageFilePrefix . 'bodytext_formlabel,
--div--;' . $frontendLanguageFilePrefix . 'tabs.appearance,
--palette--;' . $frontendLanguageFilePrefix . 'palette.frames;frames,
--palette--;;appearanceLinks,
--div--;' . $frontendLanguageFilePrefix . 'tabs.access,
--palette--;' . $frontendLanguageFilePrefix . 'palette.visibility;visibility,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
--palette--;;language,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
categories,
--div--;' . $frontendLanguageFilePrefix . 'tabs.extended,
--palette--;;hidden,
--palette--;;access,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default',
],
],
],
];
/***************
* PageTS
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:my_sitepackage_for_flipbox/Configuration/TsConfig/Page/All.tsconfig">');
在 All.tsconfig 中:從 All.tsconfig 到 ContentElements 文件夾的路徑
@import 'EXT:my_sitepackage_for_flipbox/Configuration/TsConfig/Page/ContentElements/*.tsconfig'
在 \\my_sitepackage_for_flipbox\\Configuration\\TsConfig\\Page\\ContentElements.tsconfig
# add content elements
@import 'EXT:my_sitepackage_for_flipbox/Configuration/TsConfig/ContentElements/*.tsconfig'
在 my_sitepackage_for_flipbox\\Configuration\\TsConfig\\Page\\ContentElements\\oneColumnFlipbox.tsconfig
#############################################
# Add a wizard in common #
#############################################
mod.wizards.newContentElement.wizardItems {
common {
elements {
oneColumnFlipbox {
iconIdentifier = content-dashboard
title = 1 column flipbox
description = one flipbox
tt_content_defValues {
CType = oneColumnFlipbox
}
}
}
show := addToList(oneColumnFlipbox)
}
}
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
{
$fieldName = $processorConfiguration['field'];
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'bodytext_formatted');
$highlight = GeneralUtility::makeInstance(Highlighter::class);
// Let highlight.php decide which code language to use from all registered if "detect automatically" is selected.
if (!$processedData['data']['code_language']) {
$languages = $highlight->listLanguages();
$highlight->setAutodetectLanguages($languages);
$highlighted = $highlight->highlightAuto($processedData['data'][$fieldName]);
} else {
$highlighted = $highlight->highlight($processedData['data']['code_language'], $processedData['data'][$fieldName]);
}
$processedData[$targetVariableName]['code'] = $highlighted->value;
$processedData[$targetVariableName]['language'] = $highlighted->language;
$processedData[$targetVariableName]['lines'] = preg_split('/\r\n|\r|\n/', $highlighted->value);
return $processedData;
}
###########################################
# Path #
###########################################
# add content elements
@import 'EXT:my_sitepackage_for_flipbox/Configuration/TypoScript/ContentElements/'
@import 'EXT:my_sitepackage_for_flipbox/Configuration/TypoScript/Helper/'
# Path to Templates, Partials, Layouts
lib.contentElement {
templateRootPaths {
100 = EXT:my_sitepackage_for_flipbox/Resources/Private/Templates/
}
partialRootPaths {
100 = EXT:my_sitepackage_for_flipbox/Resources/Private/Partials/
}
layoutRootPaths {
100 = EXT:my_sitepackage_for_flipbox/Resources/Private/Layouts/
}
}
在 C:\\mizuki.rasani.net\\my_sitepackage_for_flipbox\\Configuration\\TypoScript\\ContentElements\\oneColumnFlupbox.typoscript
# registering of content element for oneColumnFlipbox
tt_content {
oneColumnFlipbox =< lib.contentElement
oneColumnFlipbox {
templateName = oneColumnFlipbox
}
}
現在它顯示錯誤“糟糕,發生錯誤!代碼:20211111092555c76b0214”。
如果我使用調試在 setup-config 中通過 root 編寫代碼,則會出現錯誤:
(1/1) #1257246929 TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException
Tried resolving a template file for controller action "Standard->oneColumnFlipbox" in format ".html", but none of the paths contained the expected template file (Standard/OneColumnFlipbox.html). The following paths were checked:
/www/htdocs/w00c525b/mizuki.rasani.net/typo3/sysext/fluid_styled_content/Resources/Private/Templates/,
/www/htdocs/w00c525b/mizuki.rasani.net/typo3conf/ext/my_sitepackage_for_flipbox/Resources/Private/Templates/ContentElements/
in /www/htdocs/w00c525b/mizuki.rasani.net/typo3_src-10.4.21/vendor/typo3fluid/fluid/src/View/TemplatePaths.php line 598
我該如何解決? 我認為在排版或模板路徑中存在一些問題......但我不知道會發生什么。
我希望你能幫助我。 謝謝你。
模板名稱必須以大寫字母開頭。
# registering of content element for oneColumnFlipbox
tt_content {
oneColumnFlipbox =< lib.contentElement
oneColumnFlipbox {
templateName = OneColumnFlipbox
}
}
現在,您在此目錄中的模板EXT:my_sitepackage_for_flipbox/Resources/Private/Templates/
應該是OneColumnFlipbox.html
就是這樣,希望這對你有用。
更多...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.