[FEATURE] Named Slots
This patch enables Fluid's components to accept multiple slots. Each
slot is identified by a name argument. The corresponding
<f:fragment> ViewHelper can then be used to fill the slots of a
component.
The available slots of a component are now also exposed properly
via the ComponentDefinition DTO. Unfortunately, the TemplateParser
fails to propagate available slots of the current templates consistently to
the ParsingState, which currently leads to ugly state merging within the
parser. Hopefully, this issue can be addressed in the future to remove this
workaround, which has been documented in the code.
For this first implementation, we limit the usage if the new
<f:fragment> ViewHelper to the context of components. However, we
might expand this ViewHelper to other areas in Fluid, such as a way to
partially extend/overwrite templates.
Resolves: #1109
Possible Validations:
- If
f:fragmentis used butf:slotis not, it should trigger an Exception and notify the Developer that the slot is not defined. - If
f:slotis used but no matchingf:fragmentis used it should also trigger an Exception. (if the slot is not optional)
TBD: <f:fragment name="..."> or <f:fragment slot="...">?
TBD:
<f:fragment name="...">or<f:fragment slot="...">?
Since f:fragment might be useful in other contexts later, it's probably better to use the more generic name.
Possible Validations:
- If
f:fragmentis used butf:slotis not, it should trigger an Exception and notify the Developer that the slot is not defined.
Unfortunately, this would be a breaking change:
-
ComponentDefinitioncurrently returns a list of available slots of a component. If the underlying provider is unable to provide that information, it would need to return[]. That would mean that those components wouldn't be able to receive any slot content as this would always result in an exception. -
Existing components that fill the default slot but don't use it would trigger an exception.
I've created issue #1134 with the "breaking" label.
- If
f:slotis used but no matchingf:fragmentis used it should also trigger an Exception. (if the slot is not optional)
I don't think that we should do that. <f:slot> both defines and renders a slot, so it's possible that the definition is nested within an <f:if> or similar. So it should always be assumed that slots are optional and default to an empty string. This is also how frontend frameworks deal with slots.