Search code examples
typo3typoscriptfluidtypo3-9.x

Add fields to TYPO3 template for global site info?


How can I add some fields to the TYPO3 template (or a better location) for general site info?

For example, a phone number field so that I can add it to the site header or other non content area.

In the past I have used content elements in a special folder to add something like this, but that's not very user friendly for site editors.


Solution

  • If you want it to be (relatively) easy for site editors to edit, without building a custom module or something like that, content elements in a special folder is your best bet. We often use custom content elements for this so the field are more logical, but you do need to do some programming for this. More on creating custom fields can be found at https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html

    An alternative could be using a TypoScript constant. These are relatively easy to edit using the Constants editor in the Template module. Assuming you use Fluid templates, you can add it to your template with <f:cObject typoscriptObjectPath="lib.phoneNumber" /> In TypoScript you then add the following:

    lib.phoneNumber = TEXT
    lib.phoneNumber.value = {$phoneNumber}
    

    More about the Constants editor can be found at https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/UsingSetting/TheConstantEditor.html