Fluid gets template APIs: The new f:argument ViewHelper
Have the article read aloud.
Fluid 4.2.0 brings an exciting feature: the <f:argument> ViewHelper takes templates and partials to a new level. We can finally give our templates clear APIs.
Until now, it was sometimes a guessing game: Which variables does this partial need? What type does it expect? What happens if I forget something? The new ViewHelper solves these problems elegantly.
What does f:argument do?
You define directly in the template which variables are required, which types they have and which are optional. Fluid then automatically checks the output: Are the transferred values correct? Is something important missing? If so, there is a clear error message.
This makes templates self-documenting. A glance at the first few lines immediately reveals the complete API - i.e. which "inputs" the template has and what it expects. Perfect for teams or when you look at your own templates again after months.
My first thoughts
I find this very interesting and will certainly test it in practice soon. I see enormous potential, especially for more complex partials that are used in different contexts. Finally an end to "Why doesn't the partial work here?" - discussions.
The official documentation shows all the details, and you can find the technical background in the commit message.
What do you think about it?
Will you use the new ViewHelper?
Do you see any other use cases or potential problems?
Share your thoughts in the comments - I look forward to hearing your experiences and opinions on this exciting update!
BackDo you have a question or want to discuss the topic?
In the Community Hub for TYPO3 you can exchange ideas with other TYPO3 users. And if you don't want to miss any new articles: The TYPO3 Newsletter comes once a month, without spam.