The <<.wlink TranscludeWidget>> widget dynamically includes the content from another tiddler or variable, rendering it as if the transclude widget were replaced by the target content.
The <<.wlink TranscludeWidget>> widget can be used to render content of any type: wikitext, images, videos, etc.
Transclusion is the underlying mechanism for many higher level wikitext features, such as procedures, custom widgets and macros.
! Example
Here is a complete example showing the important features of the <<.wlink TranscludeWidget>> widget:
* `\procedure` defines a variable as a procedure with two parameters, ''name'' and ''age''
* The content of the procedure refers to the parameters as variables
* The <<.wlink TranscludeWidget>> widget specifies the variable to transclude, and values for the parameters.
! Legacy vs. Modern Mode
The <<.wlink TranscludeWidget>> widget can be used in two modes:
* <<.from-version "5.3.0">> ''Modern mode'' offers the full capabilities of the <<.wlink TranscludeWidget>> widget, and incorporates the functionality of the <<.wlink MacroCallWidget>> widget. It is indicated by the presence of at least one attribute starting with a dollar sign `$`
* ''Legacy mode'' offers a more limited set of capabilities. It is indicated by the absence of any attributes starting with a dollar sign `$`
Modern mode is recommended for use in new applications.
|$recursionMarker |recursionMarker |Set to ''no'' to prevent creation of [[Legacy Transclusion Recursion Marker]] (defaults to ''yes'') |
|//{attributes not starting with $}// |– |Any other attributes that do not start with a dollar are used as parameters to the transclusion |
|//{other attributes starting with $}// |– |Other attributes starting with a single dollar sign are reserved for future use |
|//{attributes starting with $$}// |– |Attributes starting with two dollar signs are used as parameters to the transclusion, but with the name changed to use a single dollar sign |
! Basic Operation
The basic operation of the <<.wlink TranscludeWidget>> widget is as follows:
|`<$transclude/>` |Transcludes the text field of the current tiddler |
|`<$transclude $variable="alpha"/>` |Transcludes the variable "alpha" (note that procedures, custom widgets and macros are all special types of variable) |
|`<$transclude $tiddler="foo"/>` |Transcludes the text field of the tiddler "foo" |
|`<$transclude $field="bar"/>` |Transcludes the field "bar" of the current tiddler |
|`<$transclude $index="beta"/>` |Transcludes the index "beta" of the current tiddler |
|`<$transclude $tiddler="foo" $index="beta"/>` |Transcludes the index "beta" of the tiddler "foo" |
Named string parameters can be passed to the <<.wlink TranscludeWidget>> widget. They are made available as variables within the transcluded text. Parameters are only supported in modern mode.
Parameters are available here as the variables <<firstParameter>> and <<secondParameter>>.
```
! Transclusion Slots
Transcluded content can define special named locations called slots. At the point of transclusion, blocks of wikitext can be passed to the <<.wlink TranscludeWidget>> widget to fill those slots.
Slots work very similarly to parameters except that they can contain structured wikitext, and not just plain text. The primary advantage of slots over parameters is that the contents do not need to be wrapped in quotation symbols, making it much simpler to pass complex structures.
For example, here we transclude the tiddler "Example" while using the <<.wlink FillWidget>> widget to pass wikitext blocks to fill the slots called "positive" and "negative":
The TranscludeWidget uses the special slot `ts-missing` to specify the content to be rendered if the transclusion target is not defined (i.e. a missing tiddler or a missing field).
Usually, the mode is determined by whether the transclude widget itself has been parsed in block or inline mode. This can be overridden with the <<.attr mode>> attribute.