【问题标题】:TYPO3 - Error by creating custom content elementTYPO3 - 创建自定义内容元素时出错
【发布时间】:2021-11-11 08:52:32
【问题描述】:

我需要您的帮助来创建自定义内容元素。 我使用 TYPO3 版本。 10.4.21,我添加了扩展(fluid_styled_content 和 sitepackage)。

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

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

我从现在开始:

  1. 在 ext_localconf.php 中添加数据银行
CREATE TABLE tt_content (
    code_language text DEFAULT '' NOT NULL
);
  1. 在 my_sitepackage_for_flipbox\Configuration\TCA\Overrides 中添加配置
// 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 中添加内容类型(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中添加编辑页面
// 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">');

在 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\Hei​​ghleightProcessing.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 中添加前端输出
###########################################
#                   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 使用 debug 编写代码,则会出现错误:

(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

我该如何解决? 我认为打字稿或模板路径有一些问题....但我不知道会发生什么。

我希望你能帮助我。谢谢。

【问题讨论】:

    标签: php typescript templates typo3


    【解决方案1】:

    模板名称必须以大写字母开头。

    # registering of content element for oneColumnFlipbox
    tt_content {
       oneColumnFlipbox =< lib.contentElement
       oneColumnFlipbox {
          templateName = OneColumnFlipbox
        }
    }
    

    现在,您在此目录中的模板 EXT:my_sitepackage_for_flipbox/Resources/Private/Templates/ 应该是 OneColumnFlipbox.html

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

    更多...

    【讨论】:

    • 感谢您的帮助!使用大写字母不起作用,但现在它起作用了!我不得不停用我的 sitepackakge-extension 并再次激活它。我不知道为什么,但它现在有效!谢谢!
    • 太棒了!缓存,这不是问题,而是功能!
    猜你喜欢
    • 2021-12-26
    • 2021-06-18
    • 2013-08-30
    • 2020-01-27
    • 2019-12-12
    • 2017-07-24
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多