融合(Typo脚本2):如何从父对象访问变量?(Fusion (Typoscript 2): How

2019-09-27 06:28发布

这是排序的后续问题如何Typo脚本2(Neos的)定义和访问本地变量?

如果我定义了一个局部变量,称为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'
        }
    }
}

在这个具体的例子:我怎样才能访问myLocalVar从内Neos.Fusion:Matcher

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

Answer 1:

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

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

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

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


文章来源: Fusion (Typoscript 2): How to access a variable from a parent object?