Search code examples
typo3typoscript

Absolute path with IMG_RESOURCE


I'm looking for a way to get an absolute path for an IMG_RESOURCE object in TypoScript. Since baseUrl is no real solution to me, simply add config.baseUrl = example.com isn't the thing I am accepting.

So, how could I solve something like this:

ogimage = FILES
ogimage{
    references {
        table = pages
        uid.data = page:uid
        fieldName = tx_csseo_og_image
    }
    renderObj = IMG_RESOURCE
    renderObj {
        file.import.data = file:current:publicUrl
        file.height < plugin.tx_csseo.social.openGraph.image.height
        file.width < plugin.tx_csseo.social.openGraph.image.width
        # this needs to be generated with an absolute URL
        stdWrap.dataWrap = <meta property="og:image" content="|" />
    }
}

Solution

  • I got a solution by myself. The point of the question was to not set the domain at any point at all. And have an absolute URL rendered from the FILES and IMG_RESOURCE objects, to be able to resize the image.

    ogimage = FILES
    ogimage{
        references {
            table = pages
            uid.data = page:uid
            fieldName = tx_csseo_og_image
        }
        renderObj = TEXT
        renderObj {
            typolink{
                parameter.stdWrap{
                    cObject = IMG_RESOURCE
                    cObject{
                        file.import.data = file:current:uid
                        file.treatIdAsReference = 1
                        file.height < plugin.tx_csseo.social.openGraph.image.height
                        file.width < plugin.tx_csseo.social.openGraph.image.width
                    }
                }
                returnLast = url
                forceAbsoluteUrl = 1
            }
            wrap = <meta property="og:image" content="|" />
        }
    }
    

    This will generate a resized image via IMG_RESOURCE and then generate an absolute url to this generated image via typolink, that will be then wrapped inside a meta-tag.