Hi everybody,
recently I’ve opened this thread Multilanguage tiddler - a use case for the new $slot and $fill widgets
to show a demo usage of the newly intruduced $fill and $slot widgets together with transclusion.
@jeremyruston replied with an encouraging comment:
“Thanks for sharing @Michael_Schroder that is an interesting application, and one which I would like to be able to make less verbose in the future.”
So I want to summarize my thoughts on what is actually overly verbose or otherwise odd with the transclusion mechanism.
Let’s start with the legacy mode
Today I searched a copy of an older TW documentation wiki on my hard disk (v.5.1.8) and re-read the documentation about transclusion, transclusion with templates and so on. I remembered that I already wondered at that time, why there wasn’t a “template” parameter for the $transclude widget? Transclusion with templates is so important for the separation of the “informational data” and the display logic, but we always have to use the short form “{{target||template}}” to use it. Using the long “$transclude”-Syntax we couln’t achive a transclusion with templates.
Most of the time this isn’t important, as the short form is faster and more intuitive to type…
Now there was introduced a modern mode for $transclude together with the new $fill and $slot widgets. $fill holds the “informational data” and $slot put it into the desired display logic. Thus $fill should be in the target tiddler (parameter: $tiddler) and $slot belongs to (a still not existend parameter: $template).
According to the actual documentation the design of $fill and $slot is but opposite: “The $slot widget is used within transcluded content to mark “slots” that the transcluding widget can fill with the $fill widget.” and “The $fill widget is used within a $transclude widget to specify the content that should be copied to the named “slot”.”
So the $fill widget now has to be inside the content of the $transclude widget. As you remember before 5.3.0 the content of $transclude were only rarely used to show a missing tiddler message. Therefore it is rather strange for anybody to adopt the idea of using the $transclude content for important data.
Beyond this the usual short form “{{target||template}}” doesn’t work with the new $fill and $slot widgets in neither direction. At least in my experiments I couldn’t get it working and the documentation also doesn’t show any example how to work with $fill and $slot in short transclude syntax.
My demo use case https://slot-and-fill-demo.tiddlyhost.com/ therefore is actually a little hack to get over these odds. In the demo I wrote the “data” in $fill widgets inside of an enclosing $transclude widget. This tiddler declares also a default parameter which then goes to the $tiddler-parameter of the $transclude. The parameter is called $tiddler but is in fact the template tiddler which holds the display logic and the $slot widgets.
With this preparation I can call a modified short transclusion syntax “{{target|template}}” from any tiddler - you should note there is only one “|” between “target” and “template” as “template” is given as a parameter to the transclusion. (see MultilanguageExampleTransclusion in the demo wiki)
This code pattern works well and is very flexible, but still a work around solution, difficult to understand and without sufficient documentation. I don’t know it this would be difficult to implement, but my impression is as follows:
$transclude should get another parameter “$template” and should expect the $slot widget inside the template data. The “$tiddler” or “$variable” should hold the target data to transclude an also the $fill widgets should be there. This would lead to a more usual syntax, better compatible with the legacy transclusion concept.
I hope that this post will give you some suggestions for further discussions about the $transclude mechanism.
best regards
Michael