Search code examples
typo3typo3-9.x

TYPO3: use TypoScript constants in content element links


We have a project where some page id's are defined centrally with TS constants. Our own controllers and fluid templates can pickup these constants and use them to generate links to other pages. So the target page can be switched centrally by changing the TS constants value:

plugin.tx_foobar {
    # customcategory=...
    settings {
        # customSubcategory=...
        # cat=...
        fooPageUid = 21

This can be used in a fluid template to generate some link to the page with uid 21:

<a href="/index.php?id={settings.fooPageUid}"...

Is there a possibility to use the TS constant from a content elements link section?

E.g. when inserting a link in a headline CE the page picker inserts something like:

t3://page?uid=21

We'd like to use the TS constant instead of the hard-selected 21. Something like this:

t3://page?uid={settings.fooPageUid}

This is for illustration purposes as it is obviously not correct - hence this question.


Solution

  • Make the constants via TS by assigning them into the {settings} array:

    Constants:

    plugin.tx_foobar.settings.myConstant = 123

    Setup:

    plugin.tx_foobar.settings.myConstant = {$plugin.tx_foobar.settings.myConstant}

    Then use {settings.myConstant} in Fluid and pass this as pageUid or parameter argument, whichever the ViewHelper requires.

    Is there a possibility to use the TS constant from a content elements link section?

    No, there is not, but it might be possible to override the PHP class that generates the "link wizard" popup and add a tab, make a different selector or other customisation.