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

(Peter Kurz) #1


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

            type: TYPO3\Media\Domain\Model\ImageInterface
                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?

(Christian Müller) #2

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

(Peter Kurz) #3


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?

(Aske Ertmann) #4

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.

(Peter Kurz) #5

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"

(kemal özkan) #6

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: http://neos.readthedocs.io/en/stable/References/NeosFusionReference.html#neos-fusion-case but it didn’t help to solve the problem.

(Rene Rehme) #7

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

(kemal özkan) #8

@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.