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

左心房为你撑大大i 提交于 2020-01-15 10:36:47

问题


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'}


回答1:


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'
}


来源:https://stackoverflow.com/questions/42930060/fusion-typoscript-2-how-to-access-a-variable-from-a-parent-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!