Can I get template-based transclusions to stick to lowest level in nested contexts?

48 views
Skip to first unread message

springer

unread,
Dec 28, 2019, 7:07:39 PM12/28/19
to TiddlyWiki
Dear all, here's upgrade-troubleshooting post #3, with apologies if I failed to find an existing answer...

The power of transcluded template tiddlers is enormous, and yet I'm frustrated by what happens when any tiddler that *uses* such a template is then itself shown within another tiddler (say, in a tab, or a table of contents structure). For example...

I have a simple {{childtabs}} template, plus a {{childtabs-vert}} variant, and one of these is transcluded at the bottom of most of my significant tiddlers (replacing old ForEachTiddler function). It just presents a tab for each "child" (= each tiddler tagged with the current tiddler's title). I love how quick it is to pop that string into place; I also love that tweaking the template makes the changes reverberate through all the instances. Here's the current contents of that template:

<$set name="target" filter="[<storyTiddler>get[draft.of]] [<storyTiddler>!has[draft.of]]">
<<tabs "[tag
<target>]" {{!!title}} "$:/state/tabby">>
</$set>

What I really wish for is a variant that resolves "within" the lowest-level tiddler in which it's most directly embedded. So, when I'm currently reading a "grandparent"-level tiddler (like units), each child-tab (including, say, Unit A) should ideally render just as it would if it were called up on its own, meaning it would show tabs for its own children (like Epictetus), which then may have further children, etc. (using a mix of horizontal and vertical tabs makes this surprisingly not too visually noisy). 

But as it is, trying to drill down (when the {{childtabs}} and {{childtabs-vert}} templates are in use) shows either a tab set that simply replicates the enclosing set, or a recursive transclusion error — which I especially want to avoid in a teaching resource site! (Meanwhile, other transclusions I'm using end up just showing nothing at all when the tiddler they're part of is being rendered as a tab within a tiddler that doesn't have the relevant fields.)

I realize I could explicitly spell out the rigid local tiddler title, "baking in" each use of a template, but that seems to undermine the power and simplicity of templates. Have others also wished for a tighter kind of transclusion that clings to the narrowest enclosing context...? Is it possible? Am I missing something obvious?

-Springer

PMario

unread,
Dec 29, 2019, 4:11:19 AM12/29/19
to TiddlyWiki
On Sunday, December 29, 2019 at 1:07:39 AM UTC+1, springer wrote:
...
(Meanwhile, other transclusions I'm using end up just showing nothing at all when the tiddler they're part of is being rendered as a tab within a tiddler that doesn't have the relevant fields.)

That's probably a problem mentioned here: https://tiddlywiki.com/#tabs%20Macro  See the last paragraph.

-m

PMario

unread,
Dec 29, 2019, 4:20:31 AM12/29/19
to tiddl...@googlegroups.com
On Sunday, December 29, 2019 at 1:07:39 AM UTC+1, springer wrote:
...
But as it is, trying to drill down (when the {{childtabs}} and {{childtabs-vert}} templates are in use) shows either a tab set that simply replicates the enclosing set, or a recursive transclusion error — which I especially want to avoid in a teaching resource site! (Meanwhile, other transclusions I'm using end up just showing nothing at all when the tiddler they're part of is being rendered as a tab within a tiddler that doesn't have the relevant fields.)

It seems you doing it wrong. If {{childtabs}} is a template it will set the currentTiddler variable to "childtabs".


eg: You should call it like this: {{||childtabs}} ... See the || !! Now currentTiddler in childtabs will be set to the "calling tiddler title".

!!!! Be aware of the first post, since tabs use: currentTab instead of currentTiddler.

have fun!
mario

PMario

unread,
Dec 29, 2019, 4:21:42 AM12/29/19
to TiddlyWiki
Edited last post:

It seems you doing it wrong. If {{childtabs}} is a template it will set the currentTiddler variable to "childtabs".

-m

PMario

unread,
Dec 29, 2019, 4:26:15 AM12/29/19
to TiddlyWiki
Hi,

Your templates should always use the "currentTiddler" variable. That's how TW works. If you use your own variable names, you'll end up with the problems you described, since it breaks the "transclusion chain"

If you use the list-widget, it uses currentTiddler as the default variable. ... You can set your own variable ... BUT it should only be done, if you know what you do and why.

Have a closer look a the "tab macro" implementation. ... It may help you to understand, what's going on.

-m
Reply all
Reply to author
Forward
0 new messages