Using TYPO3 site settings in TCA leads to error
08:12 26 Sep 2025

It's possible to use TYPO3 site settings in TCA SQL foreign_table_where clauses, e.g.

'config' => [
    'type' = 'select',
    'renderType' => 'selectMultipleSideBySide',
    'multiple' => true,
    'foreign_table' => 'tt_content',
    'foreign_table_where' => ' AND tt_content.deleted = 0'
        . ' AND tt_content.pid = ###SITE:settings.pages.autoelements###',
]

This works fine, but fails when a page outside a site is opened - e.g. when I have the following page tree structure:

[Root]
+ company 1 (folder)
| + site 1  (site root)
| + site 2  (site root)
+ company 2 (folder)
  + site 1  (site root)
  + site 2  (site root)  

When editing the sysfolder "company 1", the backend shows an error:

Database Error

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1. A SQL error occurred. This may indicate a schema mismatch between TCA and the database. Try running database compare in the Install Tool.

The generated SQL is

SELECT
    `tt_content`.`uid`,
    [...]
FROM
    `tt_content`,
    `pages`
WHERE
    (
        tt_content.deleted = 0 AND tt_content.pid = ###SITE:settings.pages.autoelements###
    ) AND(1 = 1) AND(`pages`.`uid` = `tt_content`.`pid`) AND(
        (
            (`tt_content`.`deleted` = 0) AND(`pages`.`deleted` = 0)
        ) AND(
            (
                (`tt_content`.`t3ver_wsid` = 0) AND(
                    (`tt_content`.`t3ver_oid` = 0) OR(`tt_content`.`t3ver_state` = 4)
                )
            ) AND(
                (`pages`.`t3ver_wsid` = 0) AND(
                    (`pages`.`t3ver_oid` = 0) OR(`pages`.`t3ver_state` = 4)
                )
            )
        )
    )

so the site settings place holder does not get replaced - there is not site configuration.


How can I prevent such SQL errors?

sql typo3 typo3-11.x tca