本文介绍了Fusion(打字稿2):如何从父对象访问变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是
如果在下面的示例中定义了一个名为myLocalVar
的局部变量,那么如何从其他对象(在本例中为Neos.Fusion:Case
)访问它呢?
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'
}
}
}
在这个具体示例中:如何从Neos.Fusion:Matcher
内部访问myLocalVar
?
In this concrete example: How can I access myLocalVar
from inside Neos.Fusion:Matcher
?
有问题的部分是条件:condition = ${???.myLocalVar[0] == 'aaa'}
The part in question is the condition: condition = ${???.myLocalVar[0] == 'aaa'}
推荐答案
您需要将myLocalVar定义为上下文变量:
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'
}
这篇关于Fusion(打字稿2):如何从父对象访问变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!