简体   繁体   English

TYPO3 TCA值作为Fluid变量

[英]TYPO3 TCA value as a variable on Fluid

I have a base extension so i can version my website. 我有一个基本扩展名,因此我可以对我的网站进行版本控制。 That means i have not a controller or a repository on the extension. 这意味着我在扩展名上没有控制器或存储库。 So what i want to do, is to create my own settings on existing elements. 因此,我想做的是在现有元素上创建自己的设置。 I was experimenting around with a text align values on the header content element. 我正在试验标题内容元素上的文本对齐值。

Keep in mind, there is already a setting for this, but i am just experimenting. 请记住,已经有一个设置,但是我只是在尝试。

I figured out how to add them and the values are saved on the database. 我想出了如何添加它们,并将值保存在数据库中。

What i now want to do, is to take the values and add them as a class on FLUID. 我现在想做的是获取值并将它们添加为FLUID上的类。 This is where i stuck. 这就是我坚持的地方。 I can not get the values. 我无法获取值。 Any idea how to do it? 知道怎么做吗?

After this guide How to enable header_position in TYPO3 7.6 i manage to get my code that far: 在完成本指南之后, 如何在TYPO3 7.6中启用header_position,我设法使代码走了这么远:

On the folder /Configuration/TCA/Overrides/tt_content.php 在文件夹/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');

On the folder /Configuration/Typoscript/Constants/Base.typoscript 在文件夹/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/

On the /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html 在/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>

I 've put the class showed just to make sure that i am reading the file from the path i gave on the constants 我把类显示出来只是为了确保我从我在常量上给出的路径中读取文件

File ext_tables.php 文件ext_tables.php

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

File ext_tables.sql 文件ext_tables.sql

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

With all these i get my selectbox where i wanted to be and i get the values on the database. 通过所有这些,我得到了我想要的选择框,并且获得了数据库中的值。 That means that if i select the value "Center" in the selectbox, then it will be saved on the database. 这意味着,如果我在选择框中选择值“ Center”,则它将保存在数据库中。 How can i get this value and use it as class on the FLUID? 如何获得该值并将其用作FLUID上的类?

Thanks in advance, 提前致谢,

You will find your field in the data object. 您将在data对象中找到您的字段。

For inspecting your fluid variables you can use the f:debug -VH: 要检查流体变量,可以使用f:debug -VH:

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

for inspecting all (in the current context) available variables you can debug _all : 要检查所有(在当前上下文中)可用变量,可以调试_all

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

Hint: use the title attribute to identify the output 提示:使用title属性来标识输出

and don't forget to write a get* and set* function for new fields! 并且不要忘记为新字段编写get*set*函数!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM