Hi,
i’m creating private variables in my components like this:
prototype(My.Site:Component.Molecule.ArticleResultCard) < prototype(Neos.Fusion:Component) {
prop1 = ''
prop2 = ''
renderer.@context.private = Neos.Fusion:DataStructure {
myVar = ${props.prop1 + ' - ' + props.prop2}
}
renderer = afx`
<div>
{private.myVar}
</div>
`
}
The problem with this solution for separating private variables from props is that private.myVar
overwrites variables with the same name in child components.
Is there a better practice?
mficzel
(Martin Ficzel)
May 16, 2021, 8:44am
2
1 Like
Thank you Martin.
That helped me a lot.
I put this in a new Fusion Object to keep the code more clean and understandable.
prototype(My.Fusion:ExtendedRenderer) < prototype(Neos.Fusion:Component) {
@apply.props = ${props}
renderer = ''
}
prototype(My.Site:Component.Atom.Button) < prototype(Neos.Fusion:Component) {
@propTypes {
// ...
}
apiProp = 'Hallo'
class = 'myClass'
renderer = My.Fusion:ExtendedRenderer {
privateProp = 'a private string'
combinedProp = ${props.apiProp + ' ' + 'Neos'}
renderer = afx`
<div class={props.class}>
{props.combinedProp}, {props.privateProp}
</div>
`
}
}
Marc
(Marc Henry Schultz)
November 1, 2022, 11:09am
4
1 Like