Fusion check if in Backend or Live/Frontend rendered

You only need any! node at hand - which doesnt matter.

via this eel you can get the wanted output.

${node.context.Live}

${node.context.InBackend}

implemented in Neos.Neos/Classes/Domain/Service/ContentContext.php

i know this exists Get “rendering in Backend” in Fusion? - Using Neos & Flow - Discuss Neos – the official forum of the Neos project but its not easily findable.

1 Like

Thanks for this info post :slight_smile:

Just a little note: It should be lower camel cased, so ${node.context.live} or ${node.context.inBackend}

1 Like

why doesnt the case matter? :sweat_smile:

I prefer using a helper like this who checks for currentRenderingMode too.
With this, the “backend” is false in Preview Mode (inside the backend).

backend = Ongoing.Base:Helper.Backend

prototype(Vendor.Project:Helper.Backend) < prototype(Neos.Fusion:Component) {
    renderer = ${node.context.inBackend && node.context.currentRenderingMode.edit ? true : false}
}
1 Like

Hi there!

Is this still true? I can’t get anything out of my nodes in NEOS 9. This is my fusion code:

prototype(dawesys.Site:Content.Image) < prototype(Neos.Neos:ContentComponent) {
    imageUri = Neos.Neos:ImageUri {
        asset = ${node.properties.image}
    }
    image = Neos.Neos:ImageTag {
        asset = ${node.properties.image}
        attributes.alt = ${node.properties.alternativeText}
    }
    dummyImage = Neos.Fusion:ResourceUri {
        path = "resource://Neos.Neos/Public/Images/dummy-image.svg"
    }
    hasCaption = ${node.properties.hasCaption}
    inBackend = ${node.context.inBackend}

    renderer = afx`
        <figure @if={props.imageUri != ""}>
            {props.image}
            <figcaption @if={props.hasCaption}>
                <Neos.Neos:Editable property="caption"></Neos.Neos:Editable>
            </figcaption>
        </figure>
        <figure @if={props.imageUri == "" && props.inBackend}>
            <Neos.Neos:ImageTag attributes.src={props.dummyImage}></Neos.Neos:ImageTag>
        </figure>
        <p>{props.inBackend}</p>
    `
}

I’m basically trying to rebuild this in Fusion.

This is one of the changes in Neos 9 the renderingMode became a global and replaced the node.context… stuff. See: Fusion API - Upgrade Instructions 8.3 → 9.0 - Version 9.x - Neos Upgrade Instructions - API - Neos Docs

In your case:

inBackend = ${node.context.inBackend}

becomes

inBackend = ${renderingMode.isEdit || renderingMode.isPreview}
1 Like

Very clean, thank you.