Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

[FEATURE] Named Slots

Open s2b opened this issue 6 months ago • 1 comments

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

s2b avatar Jun 25 '25 13:06 s2b

Possible Validations:

  1. If f:fragment is used but f:slot is not, it should trigger an Exception and notify the Developer that the slot is not defined.
  2. If f:slot is used but no matching f:fragment is used it should also trigger an Exception. (if the slot is not optional)

Kanti avatar Jun 26 '25 12:06 Kanti

TBD: <f:fragment name="..."> or <f:fragment slot="...">?

s2b avatar Jul 07 '25 17:07 s2b

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.

s2b avatar Jul 17 '25 17:07 s2b

Possible Validations:

  1. If f:fragment is used but f:slot is not, it should trigger an Exception and notify the Developer that the slot is not defined.

Unfortunately, this would be a breaking change:

  1. ComponentDefinition currently 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.

  2. 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.

  1. If f:slot is used but no matching f:fragment is 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.

s2b avatar Jul 17 '25 17:07 s2b