neoscmstyposcript2

Fusion (Typoscript 2): How to access a variable from a parent object?


This is sort of a follow-up question for How to define and access local variable in Typoscript 2 (Neos)?

If I define a local variable, called myLocalVar in the example below, how can I access it from other objects, in this case from Neos.Fusion:Case?

prototype(Some.Namespace:SomeNodeType) < prototype(TYPO3.Neos:Content) {
    myLocalVar = ${String.split(q(node).property('example'), '/', 2)}

    myResult = Neos.Fusion:Case {
        a = Neos.Fusion:Matcher {
            condition = ${???.myLocalVar[0] == 'aaa'}
            renderer = 'first part is aaa'
        }
        b = Neos.Fusion:Matcher {
            condition = ${???.myLocalVar[0] == 'bbb'}
            renderer = 'first part is bbb'
        }
    }
}

In this concrete example: How can I access myLocalVar from inside Neos.Fusion:Matcher?

The part in question is the condition: condition = ${???.myLocalVar[0] == 'aaa'}


Solution

  • You need to define your myLocalVar as context variable:

    @context.myLocalVar = ${String.split(q(node).property('example'), '/', 2)}
    

    the context is inherited by all nesting objects, so you can just access the value like this

    a = Neos.Fusion:Matcher {
        condition = ${myLocalVar[0] == 'aaa'}
        renderer = 'first part is aaa'
    }