Search code examples
typo3typoscripttypo3-8.xtypo3-8.7.x

TYPO3 - Return title & sitename if the browsertitle (tx_metaseo_pagetitle_rel) is not set


How can I use the title & sitename if the Browsertitle (tx_metaseo_pagetitle_rel) is not set?

The below always returns the sitename as well ...

page.headerData {
    5 = TEXT
    5 { 
        field = tx_metaseo_pagetitle_rel
        ifEmpty.field = title
        noTrimWrap = |<title>| - |
    }
    10 = TEXT
    10.data = GLOBAL:TYPO3_CONF_VARS|SYS|sitename
    20 = TEXT
    20.value = </title>         
}

Solution

  • in TYPO3 you have multiple options to use a field and, in case of empty value, use another.
    And you should avoid splitting tags to different objects.

    my attempt for your example would be:

    page.headerData {
        10 = COA
        10 {
            wrap = <title>|</title>
    
            10 = TEXT
            10.field = tx_metaseo_pagetitle_rel // title
    
            20 = TEXT
            20.data = GLOBAL:TYPO3_CONF_VARS|SYS|sitename
            20.noTrimWrap = | - ||
        }
    }
    

    rereading your question I came up with the the idea:
    you want either only the value of the field tx_metaseo_pagetitle_rel or the page title with the sitename attached.
    That would result in a different typoscript:

    page.headerData {
        10 = TEXT
        10 {
            wrap = <title>|</title>
    
            field = tx_metaseo_pagetitle_rel
            ifEmpty.cObject = TEXT
            ifEmpty.cObject {
                value = {field:title} - {GLOBAL:TYPO3_CONF_VARS|SYS|sitename}
                insertData = 1
            }
        }
    }