Fusion(打字稿 2):如何从父对象访问变量?

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

这是

的后续问题

如果我定义了一个局部变量,在下面的示例中称为 myLocalVar,我如何从其他对象访问它,在本例中是从 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'
        }
    }
}

在这个具体示例中:如何从 Neos.Fusion:Matcher 内部访问 myLocalVar

问题部分是条件:condition = ${???.myLocalVar[0] == 'aaa'}

您需要将 myLocalVar 定义为上下文变量:

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

上下文被所有嵌套对象继承,所以你可以像这样访问值

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