0
votes

I'm writing an extensio in Typo3 9.5 and I can't get the setup.txt or setup.typoscript to load.

I am trying to add a second page type that renders only JSON. For that I gather I need to change the typoscript. Therefore I added this code to my setup.typoscript:

ajax_ajaxjson = PAGE
ajax_ajaxjson {
    typeNum = 1

    config {
        disableAllHeaderCode = 1
        additionalHeaders = {
            10 {
                header = Content-Type: application/json
                replace = 1
            }
        }
        xhtml_cleaning = 0
        debug = 0
        no_cache = 1
        admPanel = 0
    }

    10 < tt_content.list.20.tx_energieportal_ajaxjson
}

(in EXT:\Configuration\TypoScript\setup.txt)

Now when trying to load that page type, I get the following error:

TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
The page is not configured! [type=1][]. This means that there is no TypoScript object of type PAGE with typeNum=1 configured.

I also added a test variable, and when rendering that variable with

<f:cObject typoscriptObjectPath="testvar"/>

I get the error:

No Content Object definition found at TypoScript object path "testvar"

I setup my sys_template.php up like this:

<?php
defined('TYPO3_MODE') or die();

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
    'energieportal',
    'Configuration/TypoScript',
    'Energieportal Frontend'
);

(in EXT:\Configuration\TCA\sys_template.php).

I also tried renaming the setup.txt to setup.typoscript.

Is there anything else I need to do to have my module load the setup.typoscript? I looked at the docs and other modules, but I couldn't find anything for setting up that file.

I used the search function, but the only similar question wasn't really answered. (Link)

2

2 Answers

1
votes

If you want to override the TCA of existing tables, you need to put the file into Configuration/TCA/Overrides/.

So, the correct path for your sys_template.php needs to be Configuration/TCA/Overrides/sys_template.php.

0
votes

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile only adds it to the list of static TypoScript files which can be loaded in a TypoScript template. It does not load the TypoScript file automatically.

You will have to include it in a TypoScript template in the TYPO3 backend. You can find the available static templates in the Includes tab under Include static (from extensions).

Alternatively you can include it in a different TypoScript file that is already loaded in the previously mentioned way using @import 'EXT:EXT:energieportal/Configuration/TypoScript/setup.typoscript' or <INCLUDE_TYPOSCRIPT: source="FILE:EXT:energieportal/Configuration/TypoScript/setup.typoscript">

It is also possible to add TypoScript directly from PHP using \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('My TypoScript'), so you can add the @import or <INCLUDE_TYPOSCRIPT...> line there. You can add this in your extension's ext_localconf.php or Configuration\TCA\Overrides\sys_template.php. It is however usually not recommended as you might not want the TypoScript loaded for all pages and/or sites in a TYPO3 installation.