Skip to content

Instantly share code, notes, and snippets.

@mficzel
Last active June 2, 2024 15:13
Show Gist options
  • Save mficzel/5c9c8e54f5a327123f07d762b34e2053 to your computer and use it in GitHub Desktop.
Save mficzel/5c9c8e54f5a327123f07d762b34e2053 to your computer and use it in GitHub Desktop.
Wrapper components
prototype(Vendor.Site:Example) < prototype(Neos.Fusion:Component) {
foo = null
bar = null
renderer = Neos.Fusion:Component {
# pass all outer props to the renderer
@apply.props = ${props}
# alternatively pass explicit props to the renderer
foo = ${props.foo}
# calculate additional props based on outer props
barTransformed = Neos.Fusion:Map {
items = ${props.bar}
itemRenderer = ...
}
renderer = afx`...`
}
}
@bwaidelich
Copy link

Just for the record, an alternative syntax using @context:

prototype(Vendor.Site:Example) < prototype(Neos.Fusion:Component) {
  foo = null
  bar = null
  renderer.@context {
    foo = ${props.foo}
    barTransformed = Neos.Fusion:Map {
      items = ${props.bar}
      itemRenderer = ...
    }
  }
  renderer = afx`...`
}

@mficzel
Copy link
Author

mficzel commented Apr 3, 2020

That is not exactly equivalent as @context is available in the whole chain below while props are evaluated fresh for each component.
In usual cases it may look equivalent but has some important deviations.

@bwaidelich
Copy link

OK, good call. I like the brevity of it, but it's not the same you're right

@bwaidelich
Copy link

FYI: in the meantime private props can be used to achieve the same without the drawbacks mentioned above

@mficzel
Copy link
Author

mficzel commented Jun 2, 2024

Totally agree @private is nowadays the way to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment