This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Field Transclusions

 16th October 2024 at 7:06am

Field transclusions are much like variable or procedure transclusions, but their value comes from the contents of a field of another tiddler in your wiki.

If we write {{JaneDoe!!phone}}, the contents of the phone field of the JaneDoe tiddler – namely, Jane's phone number – will appear in the output. Let's start a tiddler called PhoneNumbers in our example wiki and try that:

* JaneDoe -- {{JaneDoe!!phone}}

You should see:

  • JaneDoe – 888-555-1234

Either the left or the right side of the reference can be left off. Just {{JaneDoe}} refers to the text field of the JaneDoe tiddler, while just {{!!phone}} refers to the phone field of the current tiddler.

As soon as you update a field of a tiddler, any open tiddlers or parts of the interface that transclude that field will be automatically re-rendered – just like with the results of a filter, or the formulas in a spreadsheet. Because of the draft mechanism, though, if you're editing a tiddler within the story river, you have to save that tiddler before the changes appear – while you edit a tiddler in the story river, you're not actually editing that tiddler itself, but rather a draft copy of it, and your changes only go into the actual tiddler when you save.

Just like you can use the value of a variable or the result of a procedure call as an attribute of a widget, you can use the value of a field transclusion as an attribute of a widget. For example, suppose we had a field on the current tiddler called wikipedia-reference that contained the name of a Wikipedia article it was based on, and we wanted to create a link to it using the wikipediaLink procedure:

<$transclude $variable="wikipediaLink" article={{!!wikipedia-reference}} />

Notice the similarity in form between the three wikitext methods we've encountered for referring to other content:

  • [[double square brackets]] – to link to content
  • <<double angle brackets>> – to transclude content from a variable or procedure
  • {{double curly braces}} – to transclude content from a tiddler field

Directly transcluding entire tiddlers within other tiddlers, like {{My Other Tiddler}}, is uncommon in most wikis; linking is usually a more useful way of relating ideas. However, field transclusion is invaluable in combination with filters for creating dynamic lists, tables, and other content. In fact, the whole interface of TiddlyWiki is actually created by transcluding a bunch of special tiddlers! Field transclusion becomes even more useful once you understand templates, which we'll cover in the next section.

A note on terminology

In non-technical contexts, people sometimes use the term transclusion by itself to refer specifically to a field transclusion. Grok TiddlyWiki used to do this too, but with the introduction of new features in recent versions of TiddlyWiki that have made all kinds of transclusion more like each other (e.g., the parameterization of tiddlers), it now seems better to instead use transclusion to mean any or all kinds of transclusion, and explicitly say field transclusion when we mean that. It's possible there may be a few traces of the old way still hanging out throughout the book – please use the send feedback link to let me know if you spot one!

The $transclude widget

In the previous section, The Finer Points of Procedures we mentioned that you can use the $transclude widget with the $variable parameter to call a procedure (transclude the value of the procedure/variable). You can use the $transclude widget to do field transclusion as well, using its $tiddler and $field parameters. These are the same thing:

* {{JaneDoe!!phone}}
* <$transclude $tiddler="JaneDoe" $field="phone"/>

You can leave out one or both of the parameters if appropriate. If not supplied, $tiddler defaults to the current tiddler and $field defaults to text.

Exercises

Exercise: (m) [Ex:JaneDataTransclusion]

One of the complaints we had about our Contact Tiddlers when we initially created them was that you couldn't see any of the fields on them without clicking on the info button. Remedy that by adding a section to the JaneDoe tiddler titled Information about Jane, containing a bulleted list or table that shows Jane's email address, phone number, family members, and manager.

go to answer

Exercise: (s) [Ex:FudgeTransclusion]

Our initial motivation for extracting the now-infamous fudge tiddler from the EmployeeProfileSetupMeeting tiddler was so that we wouldn't accidentally share that information with somebody. Suppose that everyone else at the company also uses TiddlyWiki, so we always share our notes as raw wikitext instead of rendered/formatted output so recipients can paste it directly into their own wikis. In this case, we can rely on transclusion to protect us provided that the fudge tiddler's title isn't too revealing: if we copy the whole tiddler without noticing this inclusion, the recipient won't get the transcluded tiddler and thus won't see our embarrassing notes.

All this is to say, transclude the fudge tiddler into the EmployeeProfileSetupMeeting tiddler. What are the advantages and disadvantages of doing it this way as opposed to linking or tagging?

go to answer

Exercise: (s) [Ex:SearchingInTransclusions]

In an exercise in the previous chapter, we observed that tiddlers referenced in fields did not appear in search. Now, however, in Ex:JaneDataTransclusion, we transcluded the manager field directly into the JaneDoe tiddler. Try searching for some of the text in that field again (e.g., ChrisSmith). Has anything changed?

go to answer

Exercise: (s) [Ex:LinkingInTransclusions]

In general, if we reference ChrisSmith in the manager field of the JaneDoe tiddler, Jane does not show up as a backlink in ChrisSmith's Backlinks tab on the info page, because Backlinks shows only links in the text field. However, now we have a link in the text since we have transcluded the value of the manager field into the text. So now that we have a link, we should have a reference back to JaneDoe from ChrisSmith.

Test this hypothesis by looking in the Backlinks tab of ChrisSmith. What did you find? Why might this be?

go to answer

Exercise: (s) [Ex:MultipleTransclusion]

What happens if you transclude a tiddler that contains transclusions?

go to answer

Exercise: (s) [Ex:SelfTransclusion]

What happens if you transclude a tiddler into itself?

go to answer

Exercise: (s) [Ex:CircularTransclusion]

What happens if you transclude tiddler A into tiddler B, and tiddler B into tiddler A?

go to answer

Exercise: (M) [Ex:JaneManagerPhone]

Transclude a line into the text of Jane's tiddler that contains Chris Smith's phone number, in case she messes up so badly that you need to contact her manager immediately.

Can you make it so that it currently refers to Chris's phone number, but if the manager field is updated, the new manager's phone number will appear instead, without having to change the transclusion?

go to answer

Exercise: (s) [Ex:VariableTransclusion]

What happens if you set a variable in one tiddler, and transclude a tiddler that references that variable within the scope of the $set or $let widget? You can start with a Tiddler 1 that looks something like this:

<$let myVariable="test">
    {{Tiddler 2}}
</$let>
go to answer

Takeaways

Takeaways are not available in the static version of Grok TiddlyWiki. Visit the wiki version of this page to study takeaways.

↑ 4: Transclusion