【问题标题】:TYPO3 TCA value as a variable on FluidTYPO3 TCA 值作为流体上的变量
【发布时间】:2018-05-23 07:43:36
【问题描述】:

我有一个基本扩展,因此我可以对我的网站进行版本控制。这意味着我在扩展上没有控制器或存储库。所以我想做的是在现有元素上创建我自己的设置。我正在尝试在标题内容元素上使用文本对齐值。

请记住,已经有一个设置,但我只是 实验。

我想出了如何添加它们并将值保存在数据库中。

我现在想要做的是获取这些值并将它们作为一个类添加到 FLUID 上。这就是我卡住的地方。我无法获得价值。知道怎么做吗?

本指南之后How to enable header_position in TYPO3 7.6 我设法得到我的代码:

在文件夹 /Configuration/TCA/Overrides/tt_content.php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position_custom' => [
        'exclude' => 1,
        'label' => 'header position',
        'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'items' => [
                        ['left', 'left'],
                        ['right', 'right'],
                        ['center', 'center']
                ]
        ]
]   
]);

ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position_custom', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position_custom', 'after:header_layout');

在文件夹 /Configuration/Typoscript/Constants/Base.typoscript

styles.templates.templateRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Templates/
styles.templates.partialRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Partials/
styles.templates.layoutRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Layouts/

在 /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html

<h1 class="{positionClass} {header_position_custom} {data.header_position_custom} showed">
    <f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>

我把课程展示出来只是为了确保我正在阅读 来自我在常量上给出的路径的文件

文件 ext_tables.php

TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Website Base');

文件 ext_tables.sql

CREATE TABLE tt_content (
   header_position_custom varchar(255) DEFAULT '' NOT NULL,
);

通过所有这些,我得到了我想要的选择框,并且我得到了数据库中的值。这意味着如果我在选择框中选择值“中心”,那么它将保存在数据库中。如何获取此值并将其用作 FLUID 上的类?

提前致谢,

【问题讨论】:

    标签: php class typo3 typoscript fluid


    【解决方案1】:

    您将在 data 对象中找到您的字段。

    要检查您的流体变量,您可以使用f:debug-VH:

    <f:debug title="the data">{data}</f:debug>
    

    为了检查所有(在当前上下文中)可用的变量,您可以调试_all

    <f:debug title="all data">{_all}</f:debug>
    

    提示:使用title 属性来识别输出

    别忘了为新字段编写 get*set* 函数!

    【讨论】:

    • 我调试了 {data} 变量,结果为 NULL。我应该把它写在我的问题上。 get* 和 put* 是什么意思????
    • 应该有东西(试试{_all}),否则你的对象根本无法渲染。请务必从基类继承并为您的字段添加 getter 和 setter。
    • 我认为我的对象没有被渲染。这就是我得到的。 prntscr.com/jlhkcm我应该把getter和setter放在哪里?
    • 您可以使用ext:extension_builder 来构建一个扩展原型,该扩展只向现有记录添加一个字段(例如tt_content)。请参阅声明和继承。
    • 好吧,通常getter和setter都写在/Class/Domain/Model/File.php上,因为我根本不使用任何Class,还有其他方法吗?
    猜你喜欢
    • 2017-07-14
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多