Search code examples
phptypo3fluidfal

Auto-fill “alt”-text with imagefile name by using typoscript?


I want to add alt text for all images that are included from TYPO3 backend using typoscript.

<img title="ABC" alt="....." src="fileadmin/uploads/abc/nature.jpg">

Please share if anyone have answer regarding this.


Solution

  • You can automatically add alt text for all images uploaded by fal or by rte using below typoscript code in template setup file.

    temp.altText >
    temp.altText < tt_content.image.20.1.altText
    tt_content.image.20.1.altText >
    tt_content.image.20.1.altText.cObject = COA
    tt_content.image.20.1.altText.cObject {
        10 < temp.altText
        20 = TEXT
        20 {
            noTrimWrap = | | |
            data = file:current:name
        }
    }
    
    if you want to add page title in alt text of images then use below code
    
    temp.altText >
    temp.altText < tt_content.image.20.1.altText
    tt_content.image.20.1.altText >
    tt_content.image.20.1.altText.cObject = COA
    tt_content.image.20.1.altText.cObject {
        10 < temp.altText
        20 = TEXT
        20 {
            noTrimWrap = | | |
            data = page:title
        }
    }