[SOLVED] Extending the Page: TYPO3\Media\Domain\Model\Image could not be converted to string

Good morning,

like in the docs I want to add a page background in Neos 2.3.

Part of my Sites/Vendor.Site/Configuration/NodeTypes.yaml:

'TYPO3.Neos.NodeTypes:Page':
  ui:
    inspector:
      groups:
        layout:
          label: 'Layout'
        background:
          label: 'Background'
          position: 900
  properties:
    layout:
      ui:
        inspector:
          group: layout
          editorOptions:
            values:
              'default':
                label: 'Default'
              'landingPage':
                label: 'Landing Page'
    subpageLayout:
      ui:
        inspector:
          group: layout
          editorOptions:
            values:
              'default':
                label: 'Default'
              'landingPage':
                label: 'Landing page'
    backgroundImage:
      type: TYPO3\Media\Domain\Model\ImageInterface
      ui:
        label: 'Image'
        reloadPageIfChanged: TRUE
        inspector:
          group: 'background'

Part of my Sites/Vendor.Site/Resources/Private/TypoScripts/Library/Root.ts2:

prototype(TYPO3.Neos:Page) {
    backgroundImage = ${q(node).property('backgroundImage')}
}

In my Sites/Vendor.Site/Resources/Private/Templates/Page/Default.html I added this in the body section:

<div id="backgroundimage">
    <f:if condition="{backgroundImage}">
        <f:render partial="BackgroundImage" arguments="{_all}" />
    </f:if>
</div>

And my Sites/Vendor.Site/Resources/Private/Templates/Page/Partials/BackgroundImage.html looks like that:

{namespace media=TYPO3\Media\ViewHelpers}
<style>
html {
    margin:0;
    padding:0;
    background: url({media:uri.image(image:backgroundImage)}) no-repeat center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
</style>

I get the folowing exception:

An exception was thrown while Neos tried to render your page

Catchable Fatal Error: Object of class TYPO3\Flow\Persistence\Doctrine\Proxies\__CG__\TYPO3\Media\Domain\Model\Image could not be converted to string in /var/www/html/vendor/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/TYPO3_TypoScript_TypoScriptObjects_ArrayImplementation.php line 40
page<TYPO3.Neos:Page>/
For a full stacktrace, open Data/Logs/Exceptions/201702160644336243aa.txt

Does anybody have an idea, why?

You declared backgroundImage as part of the whole page not as part of the body, therefore it’s evaluated as part of the Page Array object, and thus converted to string. you need to do body.backgroundImage = .....

1 Like

Hi Christian,

I knew that I made a stupid mistake… :sleeping:

Thank you very much for the quick response.