简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM