Transcluding Children with Their Titles

Maybe someone can help me get started…

I have a tiddler with a vtab in it (I’m using it for alphabetical lists, like contacts etc).
For each letter I have a tiddler that is tagged to show in the vtab.

I want each letter to translude its children (Via tag - so you can use the tabs OR the TOC), including their titles and an HR between them. I’m thinking it would be a macro and I pass in the current tiddler’s title for identifying its children (Or I could have it list a different tiddler’s children this way).

I’m not sure how I would go about looping through the children etc, getting their titles and transluding them etc.

Thank you!

Assuming that you want each tab to display the same type of content, I’d add template:"AlphabeticalIndex" (if you’re using <<tabs...>>) or template="AlphabeticalIndex" (if you’re using <$macrocall $name="tabs" ... /> or <$transclude $variable=tabs ... />). Then make a separate template tiddler called AlphabeticalIndex:

<$tiddler tiddler=<<currentTab>>>
<$list filter="[tag<currentTiddler>]">

!!! <$link/>
<$transclude mode=block />
<hr>
</$list>
</$tiddler>

Notes:

  • The name of the current tab is stored in the variable <<currentTab>> (not <<currentTiddler>>—this remains the name of the tiddler hosting the tab set). So we’ll start out by using the $tiddler widget to set <<currentTiddler>> = <<currentTab>>. (As a bonus, this $tiddler widget won’t have any effect if the <<currentTab>> variable is undefined, so if you like, you can use this same template as a ViewTemplate on the letter tiddlers themselves, outside the tabs context.)
  • The $list widget uses a filter to make a list of tiddler titles and then applies the same template—whatever you include between <$list>...</$list>—to each of them. Within the template, the <<currentTiddler>> variable refers to the current list item, unless you specify another variable name to use. Here, I’ve made a very basic list template that will render
    1. a link to the tiddler, styled as a <h3> header. (Note the blank line above the header; this is needed to preserve block mode wikitext like the header!)
    2. the transcluded contents of that tiddler’s text field: <$transclude/> defaults to tiddler=<<currentTiddler>> field=text unless otherwise specified. {{!!text}} would retrieve the same content, but I generally like to use <$transclude mode=block /> instead to make sure that any formatting you used in the transcluded tiddler is properly preserved.
    3. an <hr>. Self-explanatory!

I used a very simple filter, [tag<currentTiddler>]: this means that the “A” tab will display all the tiddlers (and only the tiddlers) with the tag “A”. But it’s possible to write a filter for nearly any set of tiddlers you can think of. And in fact, since we’re displaying a template, not the contents of the “A” tiddler, “A” doesn’t even need to be an extant tiddler: <<currentTab>> alone will give us all the information we need for this type of display.

This is a very quick and basic overview; if you have any further questions, please feel free to ask!

2 Likes

This works great! - I’ll work on implementation - either template or macro etc.
Thank you so much!

1 Like

Do note that the template used to render the tab contents needs to be a separate tiddler (so you can’t use a macro as your tab template, for instance.) You could store the <<tabs>> macrocall itself in another macro if you want to use the same index in multiple places, though—or just transclude the tiddler that contains the <<tabs>>, which will likely be a little more efficient.

1 Like

I currently have my tabs defined in a macro. One for vertical tabs and one for horizontal ones. And I pass in the tag I want to use for the tabs instance.