I have a template tiddler:
tags: $:/tags/ViewTemplate
title: $:/user/viewtemplate/test
body: test
test shows up in the body of every tiddler except tiddlers inside of a tab macro. How can I accomplish this? I am trying to template tiddlers in my notebook but I leverage the tab macro a lot.
In the below, I see the work test in the tiddler but test does not populate in the body of the selected tiddlers in the tab macro tagged with Recipes
tags:
title: Test
body: <<tabs [tag[Recipes]]>>
By default, the <<tabs>> macro only transcludes the text field of the current tab. To have it transclude additional content (such as your $:/user/viewtemplate/test), the <<tabs>> macro needs to specify a custom tab template, like this:
<<tabs "[tag[Recipes]]" template:"$:/user/myTabsTemplate">>
where $:/user/myTabsTemplate contains something like this:
<$tiddler tiddler=<<currentTab>>>
{{!!text}}
{{||$:/user/viewtemplate/test}}
Notes:
- The
$tiddler macro sets the currentTiddler to match the currentTab value (which is automatically defined by the <<tabs>> macro internals).
- This enables
{{!!text}} to transclude the body text of the currentTab tiddler.
- Then,
{{||$:/user/viewtemplate/test}} transcludes your custom view template. The leading || causes the transclusion to use the currentTab tiddler as the source of any field references
- The blank lines in
$:/user/myTabsTemplate are important to ensure that the transclusions use “block” mode to properly render things like bullet items and tables.
- When you directly view the
$:/user/myTabsTemplate tiddler, you will see a red warning that says:
Recursive transclusion error in transclude widget
This can be safely ignored, as it is simply the result of that tiddler trying to transclude its own {{!!text}} field.
enjoy,
-e
2 Likes
@EricShulman’s explanation of how the template parameter works in the tabs Macro is amazing. This gave me the logic I need for my use case - which is an Automotive/Equipment catalog.
My requirements are that the tagged tiddlers:
- Use different templates based on tiddler name
- Some have text and some do not
- Are also viewed outside of the tabs Macro
My Answer:
I opted to create 2 different template tiddlers, 1 for templating the tabs Macro macro and 1 using the tag $:/tags/ViewTemplate.
Used as the template for tabs
title: $:/user/viewtemplate/autoasset-tab
<$tiddler tiddler=<<currentTab>>>
<% if [<currentTiddler>prefix[Information for]] %>
<$transclude $tiddler="AutoAssetInformationTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Log for]] %>
<$transclude $tiddler="AutoAssetLogTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Parts for]] %>
<$transclude $tiddler="AutoAssetPartCatalogTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Tasks for]] %>
<$transclude $tiddler="AutoAssetTaskTemplate" $mode="block" />
<% endif %>
<$transclude $mode="block" />
</$tiddler>
Used as the standard $:/tags/ViewTemplate when viewing the tiddler directly
tags: $:/tags/ViewTemplate
title: $:/user/viewtemplate/autoasset-free
<% if [<currentTiddler>prefix[Information for]] :filter[tags[]tag[Auto Asset]] %>
<$transclude $tiddler="AutoAssetInformationTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Log for]] :filter[tags[]tag[Auto Asset]] %>
<$transclude $tiddler="AutoAssetLogTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Parts for]] :filter[tags[]tag[Auto Asset]] %>
<$transclude $tiddler="AutoAssetPartCatalogTemplate" $mode="block" />
<% elseif [<currentTiddler>prefix[Tasks for]] :filter[tags[]tag[Auto Asset]] %>
<$transclude $tiddler="AutoAssetTaskTemplate" $mode="block" />
<% endif %>
Notes
-
$transclude macro is used instead of {{}} shorthand which is not affected by blank lines
-
Shortcut Syntax <%if%> is used to work around applying a single template to all of the tiddlers in the tabs Macro macro