[SOLVED] Check if property of type ImageInterface is set in order to use media:uri.image

Hi,

I have a Node (superType: document) which has a property image

'My.Node':
    […]
    properties:
        'image':
            type: TYPO3\Media\Domain\Model\ImageInterface
            ui:
                label: 'image'

in my .ts2 file I wrote:

image = ${q(node).property('image')}

an in the template I wrote:

<div class="intro-header" style="background-image: url('{media:uri.image(image:image)}')">[…]</div>

This works, but a problem occurs when there is no picture set (e.g. when the page is freshly created), because image is NULL and that which yields

Argument 1 passed to TYPO3\Media\Domain\Service\AssetService_Original::getThumbnailUriAndSizeForAsset() must be an instance of TYPO3\Media\Domain\Model\AssetInterface, null given, called in /var/www/html/neos/SP/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/TYPO3_Media_ViewHelpers_Uri_ImageViewHelper.php on line 91

How can I avoid this error? I tried

<div class="intro-header" style="background-image: url('{f:if(condition: image, then: '{media:uri.image(image:image)}', else: 'http://placehold.it/1800x450')}')">[…]</div>

but this yields the error, too. Do you have any solutions?

why is the condition on articleImage ? Should be image in order to work.

Hi,

thanks for the reply. I misspelled it in this post here, sorry – I corrected it. Problems stays the same, unfortunately.

I think the problem is, that there is a check if the call of {media:uri.image(image:image)} is valid despite of it really being executed. Is this possible?

The problem is that Fluid evaluates the then argument in your if condition view helper because it’s inline. Unfortunately you have to use <f:if><:then></then><f:else>… instead to avoid it being evaluated when no images has been selected.

Thank you very much for that explanation. Unfortunately this leads to redundancy in the code.
I found another way, defining image in the ts2 file in a way that i can just write style="background-image: url('{image}')" in the template:

    image = TYPO3.TypoScript:Case {
      imageSet {
        condition = ${q(node).property('image')}
        type = "TYPO3.Neos:ImageUri"
        element.asset = ${q(node).property('image')}
      }
      fallback {
        condition = ${true}
        renderer = "http://placehold.it/1800x450"
      }
    }

Hi I’ve a simillar problem but when I try to use the final answer /post in my case,

I get

An exception was thrown while Neos tried to render your page
“Case” Fusion object only supports nested Fusion objects; no Eel expressions.

chapterNeos.Neos:Page/ bodyNeos.Fusion:Template/ parts/ menuNeos.Neos:Menu/ backgroundImageNeos.Fusion:Case/
as response.

My code :
menu = Menu{
backgroundImage = Neos.Fusion:Case {
hasImage {
condition = ${q(node).property('image')}
type = "Neos.Fusion:ImageUri"
element.asset = ${q(node).property('image')}
}
fallback {
condition = TRUE
renderer = 'http://placehold.it/300x300'
}
}

I’ve also read the documentation here: Fusion Reference — Neos CMS 8.3.x documentation but it didn’t help to solve the problem.

@alchalade Isn’t it Neos.Neos:ImageUri instead of Neos.Fusion:ImageUri ?

@renewoerz thank you for the hint.

Problem solved;
my Menu extends from the page and the backgroundImage was already defined in the page object. That was the reason why it didn’t work at all.