3

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. 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:

On the folder /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

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

<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

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

File 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. How can i get this value and use it as class on the FLUID?

Thanks in advance,

Aristeidis Karavas
  • 1,891
  • 10
  • 29

1 Answers1

1

You will find your field in the data object.

For inspecting your fluid variables you can use the f:debug-VH:

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

for inspecting all (in the current context) available variables you can debug _all:

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

Hint: use the title attribute to identify the output

and don't forget to write a get* and set* function for new fields!

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
  • i debugged the {data} variable and it came NULL. I should had written it on my question. What do you mean by get* and put*???? – Aristeidis Karavas May 23 '18 at 08:12
  • something should be there (try `{_all}`), otherwise your object can't be rendred at all. be sure to inherit from a base class and add getter and setter for your fields. – Bernd Wilke πφ May 23 '18 at 08:17
  • I think my object doesnt get rendered. That is what i get. http://prntscr.com/jlhkcm Where should i put my getters und setters? – Aristeidis Karavas May 23 '18 at 08:19
  • you can use the `ext:extension_builder` to build a prototype of an extension which adds just one field to an existing record (e.g. tt_content). see the declaratiosn and the inheritances. – Bernd Wilke πφ May 23 '18 at 08:20
  • Well, normally the getters und setters are written on the /Class/Domain/Model/File.php Since i do not use any Class at all, is there any other way? – Aristeidis Karavas May 23 '18 at 08:22
  • I don't find proof but there is an idea in my head of magic getter and setter for all fields of tt_content. So you might need a class only for the getter and setter. – Bernd Wilke πφ May 23 '18 at 08:30