What is odd about transclusion, slot and fill mechanism

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

Regarding the Transclude widget and Templates, have a read through This Thread:

  • This is incorect, the following is the long form.
<$tiddler tiddler="target">
   <$transclude tiddler=template/>
</$tiddler>
  • Attempts to improve this was somewhat blocked by backwards compatibility.
  • If tiddler= was used instead template= it would leave tiddler= free to set the current tiddler.
  • perhaps now we could introduce an optional currentTiddler= to the transclude widtet. Perhaps Target does not sound correct in this context.

I have used fill and slot extencivly in the creation of custom widgets. We use the $fill in calling the custom widget, and the $slot in the definition of the custom widget.

  • Your usage is not clear to me so I will now look at using them in transclusions.

What I do know works inside and outside transcluded tiddlers/transclusions is the parmeters widget, functions and procedures (any pragma) inside the transcluded tiddler (as a template or otherwise)

I am interested in your workaround @Michael_Schroder so thanks for sharing. But I need to take it on advisement until I learn more. I may have more to say then.

Thanks, @Brian_Radspinner and @TW_Tones Ok, until now I wasn’t aware of this long syntax with $tiddler and $transclude…

This discussion $transclude $variable --> template? is also very interesting and explains a lot…

I think the important info is from Jeremy in the $transclude $variable --> template? - #12 by jeremyruston thread.

As @pmario notes, the familiar {{currentTiddler||template}} syntax is a shortcut for a transclude widget targeting “template” nested inside a <$tiddler> widget that assigns the specified value to the currentTiddler variable.

So, the way to think about it is that the <$transclude> widget is entirely concerned with the template. There is no attribute called “template” because the other attributes $tiddler and $variable are two different types of template.

If we didn’t have the word “transclude”, it is entirely possible that we’d be calling it the <$template> widget.


Just some additional background info, for better understanding of the existing behaviour

There are 2 widgets, with have a “special” behaviour, if their connected $tiddler or $field do not exist or are empty.

The transclude-widget and the view-widget have a “fallback”. They use the body-content as a template to be used if “tiddler” or “field” do not exist.

TranscludeWidget


ts-missing is a very new variable, which was introduced with TW v5.3.0. It was the first step for much more fine grained control using $slot- and $fill-widgets