TYPO3 - 创建自定义内容元素时出错

TYPO3 - Error by creating custom content element

我需要你的帮助来创建自定义内容元素。 我使用 TYPO3 版本。 10.4.21 并且我添加了扩展(fluid_styled_content 和站点包)。

我可以为下拉列表创建向导和内容类型 (CType),但是如果我让在前端 (websie) 上显示我的内容元素,则会发生错误: Oops, an error occurred! Code: 202111110917379495faab.

模板路径可能有错误...但我不知道如何修复它。

从现在开始我做了:

  1. 在 ext_localconf.php
  2. 中添加数据库
CREATE TABLE tt_content (
    code_language text DEFAULT '' NOT NULL
);
  1. 在 my_sitepackage_for_flipbox\Configuration\TCA\Overrides
  2. 中添加配置
// 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'
);
  1. 在 tt_content.php
  2. 中添加内容类型 (CType)
// 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',
 );
  1. 在 tt_content.php
  2. 中添加编辑页面
// 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',
          ],
       ],
    ],
 ];
  1. 在 PageTS 中添加向导 在 ext_localconf.php
/***************
 * PageTS
 */
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:my_sitepackage_for_flipbox/Configuration/TsConfig/Page/All.tsconfig">');

in 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)
   }
}
  1. 在\my_sitepackage_for_flipbox\Classes\DataProcessing\HeighleightProcessing中添加数据处理。php
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;
}
  1. 在 \my_sitepackage_for_flipbox\Configuration\TypoScriptsetup.typoscript
  2. 中添加前端输出
###########################################
#                   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

就是这样,希望这对你有用。

更多...