Search code examples
typo3typoscript

Setting base href with TYPO3 TypoScript using site.base (site configuration)


For some legacy reasons I still need to add a base href tag in the header of the HTML page:

Naively, I thought this TypoScript would work:

page.headTag.append = TEXT
page.headTag.append.data = site.base
page.headTag.append.wrap = <base href="|">

Loosely based on baseURL documentation for v12.

But, this creates the following (HTML source code):

<base href="">

Double-checking if the site.base will resolve:

page >
page = PAGE
page.10 = TEXT
page.10.data = site:base
page.10.wrap = This is your base URL: |

This works! The output is:

This is your base URL: https://mysite.example.org

(The code snippet was taken verbatim from https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/SiteHandling/UseSiteInTypoScript.html#gettext)

I did not use config.baseURL because this will be deprecated in v12. I am on TYPO3 v11.

See also documentation of config.baseURL:


Solution

  • Please make sure to use the correct data value. You are using a dot instead of a colon.

    page.headTag.append = TEXT
    page.headTag.append.data = site:base
    page.headTag.append.wrap = <base href="|">
    

    https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Functions/Data.html#data-gettext