georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
264 stars 358 forks source link

Wrong ogImage condition in Opengraph.html #2516

Closed 80Quattro closed 1 month ago

80Quattro commented 1 month ago

Bug Report

Current Behavior

<f:if condition="{newsItem.firstPreview}">
    <f:then>
        <f:variable name="ogImage" value="{newsItem.firstPreview}" />
    </f:then>
    <f:else if="{newsItem.falMedia}">
        <f:variable name="ogImage" value="{newsItem.falMedia.0}" />
    </f:else>
</f:if>

<f:if condition="ogImage">
    <f:variable name="ogImagePath" value="{f:uri.image(src:'{ogImage.uid}', treatIdAsReference:1, maxWidth:'1200')}" />
    <n:metaTag
        property="og:image"
        content="{ogImagePath}"
        forceAbsoluteUrl="1" />
    <n:metaTag property="og:image:width" content="{n:imageSize(property:'width', image:'{ogImagePath}')}" />
    <n:metaTag property="og:image:height" content="{n:imageSize(property:'height', image:'{ogImagePath}')}" />
</f:if>

Condition <f:if condition="ogImage"> checks the string ogImage, not the variable. If there is no firstPreview and no falMedia, the ogImage is NULL. Condition doesn't work and f:uri.image is executed with NULL, what causes an error:

Unable to render image uri in "tt_content:12970": You must either specify a string src or a File object.

Possible Solution Fix the condition

<f:if condition="{ogImage}">